diff --git a/network-area-diagram/pom.xml b/network-area-diagram/pom.xml index 03abd081d..1930f565a 100644 --- a/network-area-diagram/pom.xml +++ b/network-area-diagram/pom.xml @@ -5,6 +5,7 @@ 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/. + SPDX-License-Identifier: MPL-2.0 --> jimfs test + diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NadParameters.java b/network-area-diagram/src/main/java/com/powsybl/nad/NadParameters.java new file mode 100644 index 000000000..8ff749fb5 --- /dev/null +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NadParameters.java @@ -0,0 +1,88 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.nad; + +import com.powsybl.iidm.network.Network; +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.SvgParameters; +import com.powsybl.nad.svg.iidm.*; + +import java.util.Objects; + +/** + * + * @author Sophie Frasnedo + */ +public class NadParameters { + + private SvgParameters svgParameters = new SvgParameters(); + private LayoutParameters layoutParameters = new LayoutParameters(); + private StyleProviderFactory styleProviderFactory = TopologicalStyleProvider::new; + private LabelProviderFactory labelProviderFactory = DefaultLabelProvider::new; + private LayoutFactory layoutFactory = new BasicForceLayoutFactory(); + private IdProviderFactory idProviderFactory = IntIdProvider::new; + + public SvgParameters getSvgParameters() { + return svgParameters; + } + + public NadParameters setSvgParameters(SvgParameters svgParameters) { + this.svgParameters = Objects.requireNonNull(svgParameters); + return this; + } + + public LayoutParameters getLayoutParameters() { + return layoutParameters; + } + + public NadParameters setLayoutParameters(LayoutParameters layoutParameters) { + this.layoutParameters = Objects.requireNonNull(layoutParameters); + return this; + } + + public StyleProviderFactory getStyleProviderFactory() { + return styleProviderFactory; + } + + public NadParameters setStyleProviderFactory(StyleProviderFactory styleProviderFactory) { + this.styleProviderFactory = Objects.requireNonNull(styleProviderFactory); + return this; + } + + public LabelProvider createLabelProvider(Network network) { + return labelProviderFactory.create(network, svgParameters); + } + + public NadParameters setLabelProviderFactory(LabelProviderFactory labelProviderFactory) { + this.labelProviderFactory = Objects.requireNonNull(labelProviderFactory); + return this; + } + + public LayoutFactory getLayoutFactory() { + return layoutFactory; + } + + public NadParameters setLayoutFactory(LayoutFactory layoutFactory) { + this.layoutFactory = Objects.requireNonNull(layoutFactory); + return this; + } + + public IdProviderFactory getIdProviderFactory() { + return idProviderFactory; + } + + public NadParameters setIdProviderFactory(IdProviderFactory idProviderFactory) { + this.idProviderFactory = Objects.requireNonNull(idProviderFactory); + return this; + } + +} diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index b1ec0be78..3e2ebf541 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -3,25 +3,18 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.nad; +import com.powsybl.commons.PowsyblException; 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; @@ -35,116 +28,74 @@ /** * @author Florian Dupuy */ -public class NetworkAreaDiagram { +public final class NetworkAreaDiagram { - private final Network network; - private final Predicate 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 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); - } - - public Network getNetwork() { - return network; - } - - public void draw(Path svgFile) { - draw(svgFile, new SvgParameters()); + private NetworkAreaDiagram() { } - public void draw(Path svgFile, SvgParameters svgParameters) { - draw(svgFile, svgParameters, new LayoutParameters()); + public static void draw(Network network, Path svgFile) { + draw(network, svgFile, new NadParameters(), VoltageLevelFilter.NO_FILTER); } - public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters) { - draw(svgFile, svgParameters, layoutParameters, new TopologicalStyleProvider(network)); + public static void draw(Network network, Writer writer) { + draw(network, writer, new NadParameters(), VoltageLevelFilter.NO_FILTER); } - 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, String voltageLevelId, int depth) { + draw(network, svgFile, new NadParameters(), VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth)); } - public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters, - StyleProvider styleProvider, LabelProvider labelProvider) { - draw(svgFile, svgParameters, layoutParameters, styleProvider, labelProvider, new BasicForceLayoutFactory()); + public static void draw(Network network, Writer writer, String voltageLevelId, int depth) { + draw(network, writer, new NadParameters(), VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth)); } - 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, List voltageLevelIds) { + draw(network, svgFile, new NadParameters(), VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds)); } - public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters, - StyleProvider styleProvider, LabelProvider labelProvider, LayoutFactory layoutFactory, - IdProvider idProvider) { - Objects.requireNonNull(svgFile); - Objects.requireNonNull(layoutParameters); - Objects.requireNonNull(svgParameters); - Objects.requireNonNull(styleProvider); - Objects.requireNonNull(layoutFactory); - Objects.requireNonNull(idProvider); - - Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter, idProvider).buildGraph(); - layoutFactory.create().run(graph, layoutParameters); - new SvgWriter(svgParameters, styleProvider, labelProvider).writeSvg(graph, svgFile); + public static void draw(Network network, Writer writer, List voltageLevelIds) { + draw(network, writer, new NadParameters(), VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds)); } - public void draw(Writer writer) { - draw(writer, new SvgParameters()); + public static void draw(Network network, Path svgFile, List voltageLevelIds, int depth) { + draw(network, svgFile, new NadParameters(), VoltageLevelFilter.createVoltageLevelsDepthFilter(network, voltageLevelIds, depth)); } - public void draw(Writer writer, SvgParameters svgParameters) { - draw(writer, svgParameters, new LayoutParameters()); + public void draw(Network network, Writer writer, Predicate voltageLevelFilter) { + draw(network, writer, new NadParameters(), voltageLevelFilter); } - public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters) { - draw(writer, svgParameters, layoutParameters, new TopologicalStyleProvider(network)); + public static void draw(Network network, Path svgFile, NadParameters param, Predicate voltageLevelFilter) { + genericDraw(network, svgFile, param, voltageLevelFilter); } - 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, NadParameters param, Predicate voltageLevelFilter) { + genericDraw(network, writer, param, voltageLevelFilter); } - public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters, - StyleProvider styleProvider, LabelProvider labelProvider) { - draw(writer, svgParameters, layoutParameters, styleProvider, labelProvider, new BasicForceLayoutFactory()); - } + private static void genericDraw(Network network, Object object, NadParameters param, Predicate voltageLevelFilter) { + Objects.requireNonNull(network); + Objects.requireNonNull(object); + Objects.requireNonNull(param); + Objects.requireNonNull(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()); - } + Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter, param.getIdProviderFactory().create()).buildGraph(); + param.getLayoutFactory().create().run(graph, param.getLayoutParameters()); + SvgWriter svgWriter = new SvgWriter(param.getSvgParameters(), param.getStyleProviderFactory().create(network), param.createLabelProvider(network)); - 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); + if (object instanceof Path svgFile) { + svgWriter.writeSvg(graph, svgFile); + } else if (object instanceof Writer writer) { + svgWriter.writeSvg(graph, writer); + } else { + throw new PowsyblException("Second argument is an instance of an unexpected class"); + } } - public String drawToString(SvgParameters svgParameters) { + public String drawToString(Network network, SvgParameters svgParameters) { try (StringWriter writer = new StringWriter()) { - draw(writer, svgParameters); + NadParameters nadParameters = new NadParameters().setSvgParameters(svgParameters); + draw(network, writer, nadParameters, VoltageLevelFilter.NO_FILTER); return writer.toString(); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/layout/AbstractLayout.java b/network-area-diagram/src/main/java/com/powsybl/nad/layout/AbstractLayout.java index fb158241e..18ae3ec49 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/layout/AbstractLayout.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/layout/AbstractLayout.java @@ -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.layout; import com.powsybl.nad.model.*; @@ -6,6 +12,10 @@ import java.util.*; import java.util.stream.Stream; +/** + * + * @author Florian Dupuy + */ public abstract class AbstractLayout implements Layout { private Map initialNodePositions = Collections.emptyMap(); diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/IdProviderFactory.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/IdProviderFactory.java new file mode 100644 index 000000000..c2ef02633 --- /dev/null +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/IdProviderFactory.java @@ -0,0 +1,21 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.nad.svg.iidm; + +import com.powsybl.nad.build.iidm.IdProvider; + +/** + * + * @author Sophie Frasnedo + */ +@FunctionalInterface +public interface IdProviderFactory { + IdProvider create(); + +} diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/LabelProviderFactory.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/LabelProviderFactory.java new file mode 100644 index 000000000..02893aace --- /dev/null +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/LabelProviderFactory.java @@ -0,0 +1,23 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.nad.svg.iidm; + +import com.powsybl.iidm.network.Network; +import com.powsybl.nad.svg.LabelProvider; +import com.powsybl.nad.svg.SvgParameters; + +/** + * + * @author Sophie Frasnedo + */ +@FunctionalInterface +public interface LabelProviderFactory { + LabelProvider create(Network network, SvgParameters svgParameters); + +} diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/StyleProviderFactory.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/StyleProviderFactory.java new file mode 100644 index 000000000..151047bc4 --- /dev/null +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/StyleProviderFactory.java @@ -0,0 +1,21 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.nad.svg.iidm; + +import com.powsybl.iidm.network.Network; +import com.powsybl.nad.svg.StyleProvider; + +/** + * + * @author Sophie Frasnedo + */ +@FunctionalInterface +public interface StyleProviderFactory { + StyleProvider create(Network network); +} diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java index 9c828352f..b5e74731b 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java @@ -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 + */ + public class BusNodeMetadata extends AbstractMetadataItem { private static final String ELEMENT_NAME = "busNode"; diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/utils/iidm/IidmUtils.java b/network-area-diagram/src/main/java/com/powsybl/nad/utils/iidm/IidmUtils.java index bdc8bbed2..5f4b2328c 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/utils/iidm/IidmUtils.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/utils/iidm/IidmUtils.java @@ -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.*; @@ -7,6 +13,12 @@ import java.util.Objects; +/** + * + * @author Florian Dupuy + * @author Luma Zamarreño + */ + public final class IidmUtils { private IidmUtils() { diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java index a08b28168..84bd027f3 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java @@ -9,30 +9,31 @@ import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; +import com.powsybl.diagram.test.Networks; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.test.*; import com.powsybl.nad.build.iidm.VoltageLevelFilter; import com.powsybl.nad.layout.LayoutParameters; import com.powsybl.nad.svg.LabelProvider; -import com.powsybl.diagram.test.Networks; 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.NominalVoltageStyleProvider; - -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import java.nio.file.FileSystem; import java.nio.file.Path; import java.util.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Thomas Adam */ class NetworkAreaDiagramTest extends AbstractTest { - protected java.nio.file.FileSystem fileSystem; + protected FileSystem fileSystem; @BeforeEach void setup() { @@ -57,14 +58,11 @@ protected LabelProvider getLabelProvider(Network network) { @Test void testDrawSvg() { Network network = Networks.createThreeVoltageLevelsFiveBuses(); - NetworkAreaDiagram nad = new NetworkAreaDiagram(network, VoltageLevelFilter.NO_FILTER); - Path svgFile = fileSystem.getPath("nad-test.svg"); - nad.draw(svgFile, - getSvgParameters(), - getLayoutParameters(), - getStyleProvider(network)); - + NadParameters nadParameters = new NadParameters() + .setSvgParameters(getSvgParameters()) + .setStyleProviderFactory(this::getStyleProvider); + NetworkAreaDiagram.draw(network, svgFile, nadParameters, VoltageLevelFilter.NO_FILTER); assertEquals(toString("/dangling_line_connected.svg"), getContentFile(svgFile)); } diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java index c5cb679b6..5a3a30158 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.nad.layout; @@ -10,6 +11,7 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.nad.AbstractTest; +import com.powsybl.nad.NadParameters; import com.powsybl.nad.NetworkAreaDiagram; import com.powsybl.nad.build.iidm.VoltageLevelFilter; import com.powsybl.nad.model.Graph; @@ -19,12 +21,9 @@ import com.powsybl.nad.svg.SvgParameters; import com.powsybl.nad.svg.iidm.DefaultLabelProvider; import com.powsybl.nad.svg.iidm.NominalVoltageStyleProvider; +import com.powsybl.nad.svg.iidm.StyleProviderFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.StringWriter; import java.util.Collections; @@ -32,6 +31,8 @@ import java.util.Set; import java.util.function.Predicate; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Luma Zamarreno */ @@ -51,6 +52,10 @@ protected StyleProvider getStyleProvider(Network network) { return new NominalVoltageStyleProvider(network); } + private StyleProviderFactory getStyleProviderFactory() { + return this::getStyleProvider; + } + @Override protected LabelProvider getLabelProvider(Network network) { return new DefaultLabelProvider(network, getSvgParameters()); @@ -75,8 +80,7 @@ private void checkLayoutWithInitialPositions(Network network) { Predicate filter = vl -> vl.getNominalV() >= 100; // Perform an initial layout with only a few voltage levels of the network - NetworkAreaDiagram initialDiagram = new NetworkAreaDiagram(network, filter); - Map initialPositions = layoutResult(initialDiagram); + Map initialPositions = layoutResult(network, filter); // Check initial points contains an entry for all voltage levels filtered network.getVoltageLevelStream().filter(filter).forEach(vl -> assertTrue(initialPositions.containsKey(vl.getId()))); @@ -91,8 +95,7 @@ private void checkLayoutWithInitialPositions(Network network) { private void checkAllInitialPositionsFixed(Network network, Map initialPositions) { // Perform a global layout with all the voltage levels in the network, // giving fixed positions for some equipment - NetworkAreaDiagram completeNetworkDiagram = new NetworkAreaDiagram(network, VoltageLevelFilter.NO_FILTER); - Map allPositions = layoutResult(completeNetworkDiagram, initialPositions); + Map allPositions = layoutResult(network, initialPositions); // Check positions of initial layout have been preserved in global layout for (Map.Entry l : initialPositions.entrySet()) { @@ -109,10 +112,9 @@ private void checkOnlySomeInitialPositionsFixed(Network network, Map fixedNodes = Set.of(initialPositions.keySet().iterator().next()); - Map allPositions = layoutResult(completeNetworkDiagram, initialPositions, fixedNodes); + Map allPositions = layoutResult(network, initialPositions, fixedNodes); // Check positions of initial layout have been preserved in global layout for (Map.Entry l : initialPositions.entrySet()) { @@ -130,22 +132,23 @@ private void checkOnlySomeInitialPositionsFixed(Network network, Map layoutResult(NetworkAreaDiagram nad) { - return layoutResult(nad, Collections.emptyMap(), Collections.emptySet(), Collections.emptyMap()); + private Map layoutResult(Network network, Predicate voltageLevelFilter) { + return layoutResult(network, Collections.emptyMap(), Collections.emptySet(), Collections.emptyMap(), voltageLevelFilter); } - private Map layoutResult(NetworkAreaDiagram nad, Map initialNodePositions, Set nodesWithFixedPositions) { - return layoutResult(nad, initialNodePositions, nodesWithFixedPositions, Collections.emptyMap()); + private Map layoutResult(Network network, Map initialNodePositions, Set nodesWithFixedPositions) { + return layoutResult(network, initialNodePositions, nodesWithFixedPositions, Collections.emptyMap(), VoltageLevelFilter.NO_FILTER); } - private Map layoutResult(NetworkAreaDiagram nad, Map fixedNodePositions) { - return layoutResult(nad, Collections.emptyMap(), Collections.emptySet(), fixedNodePositions); + private Map layoutResult(Network network, Map fixedNodePositions) { + return layoutResult(network, Collections.emptyMap(), Collections.emptySet(), fixedNodePositions, VoltageLevelFilter.NO_FILTER); } - private Map layoutResult(NetworkAreaDiagram nad, + private Map layoutResult(Network network, Map initialNodePositions, Set nodesWithFixedPositions, - Map fixedNodePositions + Map fixedNodePositions, + Predicate voltageLevelFilter ) { LayoutFactory delegateLayoutFactory = new BasicForceLayoutFactory(); PositionsLayoutFactory positionsLayoutFactory = new PositionsLayoutFactory( @@ -154,12 +157,13 @@ private Map layoutResult(NetworkAreaDiagram nad, nodesWithFixedPositions, fixedNodePositions); StringWriter writer = new StringWriter(); - nad.draw(writer, - getSvgParameters(), - getLayoutParameters(), - getStyleProvider(nad.getNetwork()), - getLabelProvider(nad.getNetwork()), - positionsLayoutFactory); + NetworkAreaDiagram.draw(network, writer, + new NadParameters() + .setSvgParameters(getSvgParameters()) + .setLayoutParameters(getLayoutParameters()) + .setStyleProviderFactory(this::getStyleProvider) + .setLayoutFactory(positionsLayoutFactory), + voltageLevelFilter); return positionsLayoutFactory.getLayoutResult().positions; } @@ -178,7 +182,7 @@ static class LayoutResult { Map initialNodePositions, Set nodesWithFixedPositions, Map fixedNodePositions - ) { + ) { this.delegateLayoutFactory = delegateLayoutFactory; this.initialNodePositions = initialNodePositions; this.nodesWithFixedPositions = nodesWithFixedPositions; @@ -233,3 +237,4 @@ public Set getNodesWithFixedPosition() { } } } + diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/svg/TieLineTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/svg/TieLineTest.java index c926c9041..bd7598fce 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/svg/TieLineTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/svg/TieLineTest.java @@ -11,6 +11,7 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.nad.*; +import com.powsybl.nad.build.iidm.VoltageLevelFilter; import com.powsybl.nad.layout.LayoutParameters; import com.powsybl.nad.svg.iidm.DefaultLabelProvider; import com.powsybl.nad.svg.iidm.NominalVoltageStyleProvider; @@ -18,6 +19,7 @@ import org.junit.jupiter.api.Test; import java.nio.file.*; +import java.util.Collections; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -57,13 +59,12 @@ void testTieLine() { @Test void testDanglingLinePaired() { Network network = EurostagTutorialExample1Factory.createWithTieLine(); - NetworkAreaDiagram nad = new NetworkAreaDiagram(network, "VLHV1", 1); Path svgFile = fileSystem.getPath("tie_line_filtered.svg"); - nad.draw(svgFile, - getSvgParameters(), - getLayoutParameters(), - getStyleProvider(network)); - + NadParameters nadParameters = new NadParameters() + .setSvgParameters(getSvgParameters()) + .setLayoutParameters(getLayoutParameters()) + .setStyleProviderFactory(NominalVoltageStyleProvider::new); + NetworkAreaDiagram.draw(network, svgFile, nadParameters, VoltageLevelFilter.createVoltageLevelsDepthFilter(network, Collections.singletonList("VLHV1"), 1)); assertEquals(toString("/tie_line_filtered.svg"), getContentFile(svgFile)); } } diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesSubstationLayout.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesSubstationLayout.java index fca127b03..d82614243 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesSubstationLayout.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesSubstationLayout.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -42,21 +43,21 @@ public CgmesSubstationLayout(SubstationGraph graph, Network network) { @Override public void run(LayoutParameters layoutParam) { - String diagramName = layoutParam.getDiagramName(); + String diagramName = layoutParam.getCgmesDiagramName(); if (!checkDiagram(diagramName, "substation " + graph.getSubstationId())) { return; } LOG.info("Applying CGMES-DL layout to network {}, substation {}, diagram name {}", network.getId(), graph.getSubstationId(), diagramName); for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { VoltageLevel vl = network.getVoltageLevel(vlGraph.getVoltageLevelInfos().getId()); - setNodeCoordinates(vl, vlGraph, diagramName, layoutParam.isUseName()); + setNodeCoordinates(vl, vlGraph, diagramName, layoutParam.isCgmesUseNames()); } for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { - vlGraph.getNodes().forEach(node -> shiftNodeCoordinates(node, layoutParam.getScaleFactor())); + vlGraph.getNodes().forEach(node -> shiftNodeCoordinates(node, layoutParam.getCgmesScaleFactor())); } - if (layoutParam.getScaleFactor() != 1) { + if (layoutParam.getCgmesScaleFactor() != 1) { for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { - vlGraph.getNodes().forEach(node -> scaleNodeCoordinates(node, layoutParam.getScaleFactor())); + vlGraph.getNodes().forEach(node -> scaleNodeCoordinates(node, layoutParam.getCgmesScaleFactor())); } } for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesVoltageLevelLayout.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesVoltageLevelLayout.java index 9116d645c..479f4a3a3 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesVoltageLevelLayout.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesVoltageLevelLayout.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -34,15 +35,15 @@ public CgmesVoltageLevelLayout(VoltageLevelGraph graph, Network network) { @Override public void run(LayoutParameters layoutParam) { VoltageLevel vl = network.getVoltageLevel(graph.getVoltageLevelInfos().getId()); - String diagramName = layoutParam.getDiagramName(); + String diagramName = layoutParam.getCgmesDiagramName(); if (!checkDiagram(diagramName, "voltage level " + vl.getId())) { return; } LOG.info("Applying CGMES-DL layout to network {}, voltage level {}, diagram name {}", network.getId(), graph.getVoltageLevelInfos().getId(), diagramName); - setNodeCoordinates(vl, graph, diagramName, layoutParam.isUseName()); - graph.getNodes().forEach(node -> shiftNodeCoordinates(node, layoutParam.getScaleFactor())); - if (layoutParam.getScaleFactor() != 1) { - graph.getNodes().forEach(node -> scaleNodeCoordinates(node, layoutParam.getScaleFactor())); + setNodeCoordinates(vl, graph, diagramName, layoutParam.isCgmesUseNames()); + graph.getNodes().forEach(node -> shiftNodeCoordinates(node, layoutParam.getCgmesScaleFactor())); + if (layoutParam.getCgmesScaleFactor() != 1) { + graph.getNodes().forEach(node -> scaleNodeCoordinates(node, layoutParam.getCgmesScaleFactor())); } } } diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayout.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayout.java index 63ceb95f6..ec258b1ab 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayout.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayout.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -50,14 +51,14 @@ public void run(LayoutParameters layoutParam) { LOG.warn("No substations in the zone: skipping coordinates assignment"); return; } - String diagramName = layoutParam.getDiagramName(); + String diagramName = layoutParam.getCgmesDiagramName(); if (!checkDiagram(diagramName, "")) { return; } // assign coordinates for (VoltageLevelGraph vlGraph : vlGraphs) { VoltageLevel vl = network.getVoltageLevel(vlGraph.getVoltageLevelInfos().getId()); - setNodeCoordinates(vl, vlGraph, diagramName, layoutParam.isUseName()); + setNodeCoordinates(vl, vlGraph, diagramName, layoutParam.isCgmesUseNames()); } for (BranchEdge edge : graph.getLineEdges()) { VoltageLevel vl = network.getVoltageLevel(graph.getVoltageLevelGraph(edge.getNode1()).getVoltageLevelInfos().getId()); @@ -65,18 +66,18 @@ public void run(LayoutParameters layoutParam) { } // shift coordinates for (VoltageLevelGraph vlGraph : vlGraphs) { - vlGraph.getNodes().forEach(node -> shiftNodeCoordinates(node, layoutParam.getScaleFactor())); + vlGraph.getNodes().forEach(node -> shiftNodeCoordinates(node, layoutParam.getCgmesScaleFactor())); } for (BranchEdge edge : graph.getLineEdges()) { - shiftLineCoordinates(edge, layoutParam.getScaleFactor()); + shiftLineCoordinates(edge, layoutParam.getCgmesScaleFactor()); } // scale coordinates - if (layoutParam.getScaleFactor() != 1) { + if (layoutParam.getCgmesScaleFactor() != 1) { for (VoltageLevelGraph vlGraph : vlGraphs) { - vlGraph.getNodes().forEach(node -> scaleNodeCoordinates(node, layoutParam.getScaleFactor())); + vlGraph.getNodes().forEach(node -> scaleNodeCoordinates(node, layoutParam.getCgmesScaleFactor())); } for (BranchEdge edge : graph.getLineEdges()) { - scaleLineCoordinates(edge, layoutParam.getScaleFactor()); + scaleLineCoordinates(edge, layoutParam.getCgmesScaleFactor()); } } } diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesDlExporterTool.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesDlExporterTool.java index d585c021f..c3c68fd0a 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesDlExporterTool.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesDlExporterTool.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -118,7 +119,7 @@ public void run(CommandLine line, ToolRunningContext context) { Network network = Network.read(inputFile); context.getOutputStream().println("Generating layout for the network ..."); - LayoutToCgmesExtensionsConverter lTranslator = new LayoutToCgmesExtensionsConverter(sFactory, vFactory, new LayoutParameters().setUseName(true)); + LayoutToCgmesExtensionsConverter lTranslator = new LayoutToCgmesExtensionsConverter(sFactory, vFactory, new LayoutParameters().setCgmesUseNames(true)); String diagramName = toolOptions.getValue(DIAGRAM_NAME).orElse(null); lTranslator.convertLayout(network, diagramName); diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesExtensionsConverter.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesExtensionsConverter.java index 51a687eb8..d607ff787 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesExtensionsConverter.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/main/java/com/powsybl/sld/cgmes/layout/LayoutToCgmesExtensionsConverter.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -47,7 +48,7 @@ public LayoutToCgmesExtensionsConverter(SubstationLayoutFactory sFactory, Voltag } public LayoutToCgmesExtensionsConverter() { - this(new HorizontalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory(new PositionByClustering()), new LayoutParameters().setUseName(true)); + this(new HorizontalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory(new PositionByClustering()), new LayoutParameters().setCgmesUseNames(true)); } private int getMaxSeq(List diagramPoints) { diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/AbstractCgmesVoltageLevelLayoutTest.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/AbstractCgmesVoltageLevelLayoutTest.java index 93d6dbcfb..d04a370a4 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/AbstractCgmesVoltageLevelLayoutTest.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/AbstractCgmesVoltageLevelLayoutTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -27,8 +28,8 @@ abstract class AbstractCgmesVoltageLevelLayoutTest { protected void test(VoltageLevel vl) { VoltageLevelGraph graph = new NetworkGraphBuilder(vl.getNetwork()).buildVoltageLevelGraph(vl.getId()); LayoutParameters layoutParameters = new LayoutParameters(); - layoutParameters.setScaleFactor(2); - layoutParameters.setDiagramName(DIAGRAM_NAME); + layoutParameters.setCgmesScaleFactor(2); + layoutParameters.setCgmesDiagramName(DIAGRAM_NAME); new CgmesVoltageLevelLayout(graph, vl.getNetwork()).run(layoutParameters); checkGraph(graph); checkCoordinates(graph); diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/BusTopologyTest.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/BusTopologyTest.java index 28401abb1..17859c507 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/BusTopologyTest.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/BusTopologyTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -313,8 +314,8 @@ void testVoltageLevelLayout() { void testSubstationLayout() { SubstationGraph graph = new NetworkGraphBuilder(network).buildSubstationGraph(substation.getId()); LayoutParameters layoutParameters = new LayoutParameters(); - layoutParameters.setScaleFactor(2); - layoutParameters.setDiagramName(DIAGRAM_NAME); + layoutParameters.setCgmesScaleFactor(2); + layoutParameters.setCgmesDiagramName(DIAGRAM_NAME); new CgmesSubstationLayout(graph, network).run(layoutParameters); checkGraph(graph.getVoltageLevel(voltageLevel.getId())); checkCoordinates(graph.getVoltageLevel(voltageLevel.getId())); @@ -467,8 +468,8 @@ private void checkSubstationTwt(SubstationGraph graph, int edgesNumber) { void testSubstationLayout3WT() { SubstationGraph graph = new NetworkGraphBuilder(networkWith3WT).buildSubstationGraph(substation2.getId()); LayoutParameters layoutParameters = new LayoutParameters(); - layoutParameters.setScaleFactor(2); - layoutParameters.setDiagramName(DIAGRAM_NAME); + layoutParameters.setCgmesScaleFactor(2); + layoutParameters.setCgmesDiagramName(DIAGRAM_NAME); new CgmesSubstationLayout(graph, networkWith3WT).run(layoutParameters); checkGraph(graph.getVoltageLevel(voltageLevel21.getId())); checkCoordinates(graph.getVoltageLevel(voltageLevel21.getId())); diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayoutTest.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayoutTest.java index a8538fb2d..1b2346cc8 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayoutTest.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/CgmesZoneLayoutTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -204,8 +205,8 @@ void test() { List zone = Arrays.asList(SUBSTATION_1_ID, SUBSTATION_2_ID); ZoneGraph graph = new NetworkGraphBuilder(network).buildZoneGraph(zone); LayoutParameters layoutParameters = new LayoutParameters(); - layoutParameters.setScaleFactor(2); - layoutParameters.setDiagramName(DIAGRAM_ID); + layoutParameters.setCgmesScaleFactor(2); + layoutParameters.setCgmesDiagramName(DIAGRAM_ID); new CgmesZoneLayout(graph, network).run(layoutParameters); assertEquals(2, graph.getSubstations().size()); diff --git a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/DoubleBusbarSectionTest.java b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/DoubleBusbarSectionTest.java index 7194d7db5..a5d91d0ce 100644 --- a/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/DoubleBusbarSectionTest.java +++ b/single-line-diagram/single-line-diagram-cgmes/single-line-diagram-cgmes-layout/src/test/java/com/powsybl/sld/cgmes/layout/DoubleBusbarSectionTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.cgmes.layout; @@ -133,8 +134,8 @@ private VoltageLevelGraph processCgmesLayout() { NetworkGraphBuilder graphBuilder = new NetworkGraphBuilder(voltageLevel.getNetwork()); VoltageLevelGraph graph = graphBuilder.buildVoltageLevelGraph(voltageLevel.getId()); LayoutParameters layoutParameters = new LayoutParameters(); - layoutParameters.setScaleFactor(1); - layoutParameters.setDiagramName(DIAGRAM_NAME); + layoutParameters.setCgmesScaleFactor(1); + layoutParameters.setCgmesDiagramName(DIAGRAM_NAME); new CgmesVoltageLevelLayout(graph, voltageLevel.getNetwork()).run(layoutParameters); return graph; } diff --git a/single-line-diagram/single-line-diagram-core/pom.xml b/single-line-diagram/single-line-diagram-core/pom.xml index 2cddea4bf..30d9576ab 100644 --- a/single-line-diagram/single-line-diagram-core/pom.xml +++ b/single-line-diagram/single-line-diagram-core/pom.xml @@ -5,6 +5,7 @@ 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/. + SPDX-License-Identifier: MPL-2.0 --> powsybl-diagram-test test + + com.powsybl + powsybl-diagram-test + test + com.powsybl powsybl-iidm-impl diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagram.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagram.java index 5000d108b..b9ab8edc2 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagram.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagram.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld; @@ -10,15 +11,15 @@ import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.Network; import com.powsybl.sld.builders.NetworkGraphBuilder; -import com.powsybl.sld.layout.*; +import com.powsybl.sld.layout.LayoutParameters; +import com.powsybl.sld.layout.VoltageLevelLayoutFactory; import com.powsybl.sld.library.ComponentLibrary; -import com.powsybl.sld.library.ConvergenceComponentLibrary; -import com.powsybl.sld.model.graphs.*; +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 com.powsybl.sld.svg.styles.iidm.HighlightLineStateStyleProvider; -import com.powsybl.sld.svg.styles.StyleProvidersList; -import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,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; @@ -43,51 +45,50 @@ public final class SingleLineDiagram { private SingleLineDiagram() { } + private static Identifiable getIdentifiable(Network network, String id) { + Identifiable identifiable = network.getIdentifiable(id); + if (identifiable == null) { + throw new PowsyblException("Network element '" + id + "' not found"); + } + return identifiable; + } + public static void draw(Network network, String id, String svgFile) { draw(network, id, Path.of(svgFile)); } public static void draw(Network network, String id, Path svgFile) { - draw(network, id, svgFile, new LayoutParameters()); + draw(network, id, svgFile, new SldParameters()); } - public static void draw(Network network, String id, Path svgFile, LayoutParameters layoutParameters) { - draw(network, id, svgFile, layoutParameters, new ConvergenceComponentLibrary()); + public static void draw(Network network, String id, Writer writerForSvg, Writer metadataWriter) { + draw(network, id, writerForSvg, metadataWriter, new SldParameters()); } - public static void draw(Network network, String id, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary) { - draw(network, id, svgFile, layoutParameters, componentLibrary, - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - createDefaultStyleProvider(network), - ""); - } + public static void draw(Network network, String id, Path svgFile, SldParameters sldParameters) { + Objects.requireNonNull(network); + Objects.requireNonNull(id); - public static void draw(Network network, String id, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - draw(network, id, svgFile, layoutParameters, componentLibrary, - new HorizontalSubstationLayoutFactory(), new SmartVoltageLevelLayoutFactory(network), - initProvider, styleProvider, prefixId); - } + Identifiable identifiable = getIdentifiable(network, id); - private static Identifiable getIdentifiable(Network network, String id) { - Identifiable identifiable = network.getIdentifiable(id); - if (identifiable == null) { - throw new PowsyblException("Network element '" + id + "' not found"); + if (identifiable.getType() == VOLTAGE_LEVEL) { + drawVoltageLevel(network, id, svgFile, sldParameters); + } else if (identifiable.getType() == SUBSTATION) { + drawSubstation(network, id, svgFile, sldParameters); + } else { + throw new PowsyblException("Given id '" + id + "' is not a substation or voltage level id in given network '" + network.getId() + "'"); } - return identifiable; } - public static void draw(Network network, String id, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vLayoutFactory, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { + public static void draw(Network network, String id, Writer writerForSvg, Writer metadataWriter, SldParameters sldParameters) { Objects.requireNonNull(network); Objects.requireNonNull(id); Identifiable identifiable = getIdentifiable(network, id); if (identifiable.getType() == VOLTAGE_LEVEL) { - drawVoltageLevel(network, id, svgFile, layoutParameters, componentLibrary, vLayoutFactory, initProvider, styleProvider, prefixId); + drawVoltageLevel(network, id, writerForSvg, metadataWriter, sldParameters); } else if (identifiable.getType() == SUBSTATION) { - drawSubstation(network, id, svgFile, layoutParameters, componentLibrary, sLayoutFactory, vLayoutFactory, initProvider, styleProvider, prefixId); + drawSubstation(network, id, writerForSvg, metadataWriter, sldParameters); } else { throw new PowsyblException("Given id '" + id + "' is not a substation or voltage level id in given network '" + network.getId() + "'"); } @@ -97,33 +98,20 @@ public static void drawVoltageLevel(Network network, String id, String svgFile) drawVoltageLevel(network, id, Path.of(svgFile)); } - public static void drawVoltageLevel(Network network, String id, Path svgFile) { - drawVoltageLevel(network, id, svgFile, new LayoutParameters()); - } - - public static void drawVoltageLevel(Network network, String id, Path svgFile, LayoutParameters layoutParameters) { - drawVoltageLevel(network, id, svgFile, layoutParameters, new ConvergenceComponentLibrary()); + public static void drawVoltageLevel(Network network, String voltageLevelId, Path svgFile) { + drawVoltageLevel(network, voltageLevelId, svgFile, new SldParameters()); } - public static void drawVoltageLevel(Network network, String id, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary) { - drawVoltageLevel(network, id, svgFile, layoutParameters, componentLibrary, - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - createDefaultStyleProvider(network), - ""); - } - - public static void drawVoltageLevel(Network network, String id, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - drawVoltageLevel(network, id, svgFile, layoutParameters, componentLibrary, new SmartVoltageLevelLayoutFactory(network), initProvider, styleProvider, prefixId); + private static void drawVoltageLevel(Network network, String voltageLevelId, Path svgFile, SldParameters sldParameters) { + VoltageLevelGraph voltageLevelGraph = new NetworkGraphBuilder(network).buildVoltageLevelGraph(voltageLevelId); + DefaultSVGWriter svgWriter = preDraw(voltageLevelGraph, sldParameters, network); + draw(voltageLevelGraph, svgFile, svgWriter, sldParameters.createLabelProvider(network), sldParameters.getStyleProviderFactory().create(network)); } - private static void drawVoltageLevel(Network network, String voltageLevelId, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - VoltageLevelLayoutFactory vLayoutFactory, DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - Objects.requireNonNull(vLayoutFactory); - + public static void drawVoltageLevel(Network network, String voltageLevelId, Writer writerForSvg, Writer metadataWriter, SldParameters sldParameters) { VoltageLevelGraph voltageLevelGraph = new NetworkGraphBuilder(network).buildVoltageLevelGraph(voltageLevelId); - vLayoutFactory.create(voltageLevelGraph).run(layoutParameters); - draw(voltageLevelGraph, svgFile, layoutParameters, componentLibrary, initProvider, styleProvider, prefixId); + DefaultSVGWriter svgWriter = preDraw(voltageLevelGraph, sldParameters, network); + draw(voltageLevelGraph, writerForSvg, metadataWriter, svgWriter, sldParameters.createLabelProvider(network), sldParameters.getStyleProviderFactory().create(network)); } public static void drawSubstation(Network network, String id, String svgFile) { @@ -131,40 +119,38 @@ public static void drawSubstation(Network network, String id, String svgFile) { } public static void drawSubstation(Network network, String id, Path svgFile) { - drawSubstation(network, id, svgFile, new LayoutParameters()); + drawSubstation(network, id, svgFile, new SldParameters()); } - public static void drawSubstation(Network network, String id, Path svgFile, LayoutParameters layoutParameters) { - drawSubstation(network, id, svgFile, layoutParameters, new ConvergenceComponentLibrary()); + private static void drawSubstation(Network network, String substationId, Path svgFile, SldParameters sldParameters) { + SubstationGraph substationGraph = new NetworkGraphBuilder(network).buildSubstationGraph(substationId); + DefaultSVGWriter svgWriter = preDraw(substationGraph, sldParameters, network); + draw(substationGraph, svgFile, svgWriter, sldParameters.createLabelProvider(network), sldParameters.getStyleProviderFactory().create(network)); } - public static void drawSubstation(Network network, String id, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary) { - drawSubstation(network, id, svgFile, layoutParameters, componentLibrary, - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - createDefaultStyleProvider(network), - ""); + public static void drawSubstation(Network network, String substationId, Writer writerForSvg, Writer metadataWriter, SldParameters sldParameters) { + SubstationGraph substationGraph = new NetworkGraphBuilder(network).buildSubstationGraph(substationId); + DefaultSVGWriter svgWriter = preDraw(substationGraph, sldParameters, network); + draw(substationGraph, writerForSvg, metadataWriter, svgWriter, sldParameters.createLabelProvider(network), sldParameters.getStyleProviderFactory().create(network)); } - public static void drawSubstation(Network network, String id, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - drawSubstation(network, id, svgFile, layoutParameters, componentLibrary, - new HorizontalSubstationLayoutFactory(), new SmartVoltageLevelLayoutFactory(network), - initProvider, styleProvider, prefixId); + public static void drawMultiSubstations(Network network, List substationIdList, Path svgFile) { + drawMultiSubstations(network, substationIdList, svgFile, new SldParameters()); } - private static void drawSubstation(Network network, String substationId, Path svgFile, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vLayoutFactory, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - Objects.requireNonNull(sLayoutFactory); - Objects.requireNonNull(vLayoutFactory); + public static void drawMultiSubstations(Network network, List 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)); + } - SubstationGraph substationGraph = new NetworkGraphBuilder(network).buildSubstationGraph(substationId); - sLayoutFactory.create(substationGraph, vLayoutFactory).run(layoutParameters); - draw(substationGraph, svgFile, layoutParameters, componentLibrary, initProvider, styleProvider, prefixId); + public static void drawMultiSubstations(Network network, List 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, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { + public static void draw(Graph graph, Path svgFile, DefaultSVGWriter svgWriter, LabelProvider labelProvider, StyleProvider styleProvider) { Objects.requireNonNull(svgFile); Path dir = svgFile.toAbsolutePath().getParent(); @@ -174,138 +160,46 @@ public static void draw(Graph graph, Path svgFile, LayoutParameters layoutParame } try (Writer writerForSvg = Files.newBufferedWriter(svgFile, StandardCharsets.UTF_8); Writer metadataWriter = Files.newBufferedWriter(dir.resolve(svgFileName.replace(".svg", "_metadata.json")), StandardCharsets.UTF_8)) { - draw(graph, writerForSvg, metadataWriter, layoutParameters, componentLibrary, initProvider, styleProvider, prefixId); + draw(graph, writerForSvg, metadataWriter, svgWriter, labelProvider, styleProvider); } catch (IOException e) { throw new UncheckedIOException(e); } } - public static void draw(Network network, String id, Writer writerForSvg, Writer metadataWriter) { - draw(network, id, writerForSvg, metadataWriter, new LayoutParameters()); - } - - public static void draw(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters) { - draw(network, id, writerForSvg, metadataWriter, layoutParameters, new ConvergenceComponentLibrary()); - } - - public static void draw(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary) { - draw(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - createDefaultStyleProvider(network), - ""); - } - - public static void draw(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - draw(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, - new HorizontalSubstationLayoutFactory(), new SmartVoltageLevelLayoutFactory(network), - initProvider, styleProvider, prefixId); - } - - public static void draw(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vLayoutFactory, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - Objects.requireNonNull(network); - Objects.requireNonNull(id); - - Identifiable identifiable = getIdentifiable(network, id); - if (identifiable.getType() == VOLTAGE_LEVEL) { - drawVoltageLevel(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, vLayoutFactory, initProvider, styleProvider, prefixId); - } else if (identifiable.getType() == SUBSTATION) { - drawSubstation(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, sLayoutFactory, vLayoutFactory, initProvider, styleProvider, prefixId); - } else { - throw new PowsyblException("Given id '" + id + "' is not a substation or voltage level id in given network '" + network.getId() + "'"); - } - } - - public static void drawVoltageLevel(Network network, String id, Writer writerForSvg, Writer metadataWriter) { - drawVoltageLevel(network, id, writerForSvg, metadataWriter, new LayoutParameters()); - } - - public static void drawVoltageLevel(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters) { - drawVoltageLevel(network, id, writerForSvg, metadataWriter, layoutParameters, new ConvergenceComponentLibrary()); - } - - public static void drawVoltageLevel(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary) { - drawVoltageLevel(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - createDefaultStyleProvider(network), - ""); - } - - public static void drawVoltageLevel(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - drawVoltageLevel(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, new SmartVoltageLevelLayoutFactory(network), initProvider, styleProvider, prefixId); - } - - private static void drawVoltageLevel(Network network, String voltageLevelId, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - VoltageLevelLayoutFactory vLayoutFactory, DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - Objects.requireNonNull(vLayoutFactory); - - VoltageLevelGraph voltageLevelGraph = new NetworkGraphBuilder(network).buildVoltageLevelGraph(voltageLevelId); - vLayoutFactory.create(voltageLevelGraph).run(layoutParameters); - draw(voltageLevelGraph, writerForSvg, metadataWriter, layoutParameters, componentLibrary, initProvider, styleProvider, prefixId); - } - - public static void drawSubstation(Network network, String id, Writer writerForSvg, Writer metadataWriter) { - drawSubstation(network, id, writerForSvg, metadataWriter, new LayoutParameters()); - } - - public static void drawSubstation(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters) { - drawSubstation(network, id, writerForSvg, metadataWriter, layoutParameters, new ConvergenceComponentLibrary()); - } - - public static void drawSubstation(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary) { - drawSubstation(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - createDefaultStyleProvider(network), - ""); - } - - public static void drawSubstation(Network network, String id, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - drawSubstation(network, id, writerForSvg, metadataWriter, layoutParameters, componentLibrary, - new HorizontalSubstationLayoutFactory(), new SmartVoltageLevelLayoutFactory(network), - initProvider, styleProvider, prefixId); - } - - private static void drawSubstation(Network network, String substationId, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vLayoutFactory, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - Objects.requireNonNull(sLayoutFactory); - Objects.requireNonNull(vLayoutFactory); - - SubstationGraph substationGraph = new NetworkGraphBuilder(network).buildSubstationGraph(substationId); - sLayoutFactory.create(substationGraph, vLayoutFactory).run(layoutParameters); - draw(substationGraph, writerForSvg, metadataWriter, layoutParameters, componentLibrary, initProvider, styleProvider, prefixId); - } - - public static void draw(Graph graph, Writer writerForSvg, Writer metadataWriter, LayoutParameters layoutParameters, ComponentLibrary componentLibrary, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { - draw(graph, writerForSvg, metadataWriter, new DefaultSVGWriter(componentLibrary, layoutParameters), - initProvider, styleProvider, prefixId); - } - - public static void draw(Graph graph, Writer writerForSvg, Writer metadataWriter, DefaultSVGWriter svgWriter, - DiagramLabelProvider initProvider, StyleProvider styleProvider, String prefixId) { + public static void draw(Graph graph, Writer writerForSvg, Writer metadataWriter, DefaultSVGWriter svgWriter, LabelProvider labelProvider, StyleProvider styleProvider) { Objects.requireNonNull(graph); - Objects.requireNonNull(svgWriter); - Objects.requireNonNull(initProvider); - Objects.requireNonNull(styleProvider); - Objects.requireNonNull(prefixId); Objects.requireNonNull(writerForSvg); Objects.requireNonNull(metadataWriter); + Objects.requireNonNull(labelProvider); + Objects.requireNonNull(styleProvider); LOGGER.info("Writing SVG and JSON metadata files..."); - // write SVG file - GraphMetadata metadata = svgWriter.write(prefixId, graph, initProvider, styleProvider, writerForSvg); - + GraphMetadata metadata = svgWriter.write(graph, labelProvider, styleProvider, writerForSvg); // write metadata JSON file metadata.writeJson(metadataWriter); } - private static StyleProvider createDefaultStyleProvider(Network network) { - return new StyleProvidersList(new TopologicalStyleProvider(network), new HighlightLineStateStyleProvider(network)); + public static void draw(Graph graph, Writer writerForSvg, Writer metadataWriter, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters, LabelProvider labelProvider, StyleProvider styleProvider) { + Objects.requireNonNull(componentLibrary); + Objects.requireNonNull(layoutParameters); + Objects.requireNonNull(svgParameters); + DefaultSVGWriter svgWriter = new DefaultSVGWriter(componentLibrary, layoutParameters, svgParameters); + draw(graph, writerForSvg, metadataWriter, svgWriter, labelProvider, styleProvider); + } + + private static DefaultSVGWriter preDraw(Graph graph, SldParameters sldParameters, Network network) { + LayoutParameters layoutParameters = sldParameters.getLayoutParameters(); + VoltageLevelLayoutFactory voltageLevelLayoutFactory = sldParameters.createVoltageLevelLayoutFactory(network); + if (graph instanceof VoltageLevelGraph voltageLevelGraph) { + voltageLevelLayoutFactory.create(voltageLevelGraph).run(layoutParameters); + } else if (graph instanceof SubstationGraph substationGraph) { + 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"); + } + return new DefaultSVGWriter(sldParameters.getComponentLibrary(), sldParameters.getLayoutParameters(), sldParameters.getSvgParameters()); } } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagramTool.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagramTool.java index f6fdddc95..c9f435289 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagramTool.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SingleLineDiagramTool.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld; @@ -11,11 +12,6 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.Substation; import com.powsybl.iidm.network.VoltageLevel; -import com.powsybl.sld.layout.*; -import com.powsybl.sld.library.ComponentLibrary; -import com.powsybl.sld.library.ConvergenceComponentLibrary; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; -import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider; import com.powsybl.tools.Command; import com.powsybl.tools.Tool; import com.powsybl.tools.ToolOptions; @@ -93,56 +89,36 @@ private Path getSvgFile(Path outputDir, String id) { } } - static class SvgGenerationConfig { - - ComponentLibrary componentLibrary = new ConvergenceComponentLibrary(); - - LayoutParameters layoutParameters = new LayoutParameters(); - - VoltageLevelLayoutFactory voltageLevelLayoutFactory; - - SubstationLayoutFactory substationLayoutFactory = new HorizontalSubstationLayoutFactory(); - - SvgGenerationConfig(Network network) { - voltageLevelLayoutFactory = new SmartVoltageLevelLayoutFactory(network); - } - } - - private void generateSvg(ToolRunningContext context, Path outputDir, SvgGenerationConfig generationConfig, - String vlOrSubstationId, Network network) { + private void generateSvg(ToolRunningContext context, Path outputDir, String vlOrSubstationId, Network network, SldParameters sldParameters) { Path svgFile = getSvgFile(outputDir, vlOrSubstationId); context.getOutputStream().println("Generating '" + svgFile + "'"); try { - SingleLineDiagram.draw(network, vlOrSubstationId, svgFile, - generationConfig.layoutParameters, generationConfig.componentLibrary, - generationConfig.substationLayoutFactory, generationConfig.voltageLevelLayoutFactory, - new DefaultDiagramLabelProvider(network, generationConfig.componentLibrary, generationConfig.layoutParameters), - new TopologicalStyleProvider(network), ""); + SingleLineDiagram.draw(network, vlOrSubstationId, svgFile, sldParameters); } catch (Exception e) { e.printStackTrace(context.getErrorStream()); } } - private void generateSome(ToolRunningContext context, Path outputDir, List ids, Network network, SvgGenerationConfig generationConfig) { + private void generateSome(ToolRunningContext context, Path outputDir, List ids, Network network, SldParameters sldParameters) { for (String id : ids) { - generateSvg(context, outputDir, generationConfig, id, network); + generateSvg(context, outputDir, id, network, sldParameters); } } private void generateAll(ToolRunningContext context, boolean allVoltageLevels, boolean allSubstations, - Path outputDir, Network network, SvgGenerationConfig generationConfig) { + Path outputDir, Network network, SldParameters sldParameters) { // by default, export all voltage levels if no id given and no // additional option (all-voltage-levels or all-substations) given if (allVoltageLevels || !allSubstations) { // export all voltage levels for (VoltageLevel vl : network.getVoltageLevels()) { - generateSvg(context, outputDir, generationConfig, vl.getId(), network); + generateSvg(context, outputDir, vl.getId(), network, sldParameters); } } if (allSubstations) { // export all substations for (Substation s : network.getSubstations()) { - generateSvg(context, outputDir, generationConfig, s.getId(), network); + generateSvg(context, outputDir, s.getId(), network, sldParameters); } } } @@ -158,13 +134,13 @@ public void run(CommandLine line, ToolRunningContext context) { if (network == null) { throw new PowsyblException("File '" + inputFile + "' is not importable"); } - SvgGenerationConfig generationConfig = new SvgGenerationConfig(network); + SldParameters sldParameters = new SldParameters(); if (ids.isEmpty()) { boolean allVoltageLevels = toolOptions.hasOption(ALL_VOLTAGE_LEVELS); boolean allSubstations = toolOptions.hasOption(ALL_SUBSTATIONS); - generateAll(context, allVoltageLevels, allSubstations, outputDir, network, generationConfig); + generateAll(context, allVoltageLevels, allSubstations, outputDir, network, sldParameters); } else { - generateSome(context, outputDir, ids, network, generationConfig); + generateSome(context, outputDir, ids, network, sldParameters); } } } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SldParameters.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SldParameters.java new file mode 100644 index 000000000..3d3ba00b3 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/SldParameters.java @@ -0,0 +1,110 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.sld; + +import com.powsybl.iidm.network.Network; +import com.powsybl.sld.layout.*; +import com.powsybl.sld.library.ComponentLibrary; +import com.powsybl.sld.library.ConvergenceComponentLibrary; +import com.powsybl.sld.svg.DefaultLabelProvider; +import com.powsybl.sld.svg.LabelProvider; +import com.powsybl.sld.svg.LabelProviderFactory; +import com.powsybl.sld.svg.SvgParameters; +import com.powsybl.sld.svg.styles.DefaultStyleProviderFactory; +import com.powsybl.sld.svg.styles.StyleProviderFactory; + +import java.util.Objects; + +/** + * + * @author Sophie Frasnedo + */ +public class SldParameters { + + private SvgParameters svgParameters = new SvgParameters(); + private LayoutParameters layoutParameters = new LayoutParameters(); + private ComponentLibrary componentLibrary = new ConvergenceComponentLibrary(); + private LabelProviderFactory labelProviderFactory = DefaultLabelProvider::new; + private StyleProviderFactory styleProviderFactory = new DefaultStyleProviderFactory(); + private VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = VoltageLevelLayoutFactoryCreator.newSmartVoltageLevelLayoutFactoryCreator(); + private SubstationLayoutFactory substationLayoutFactory = new HorizontalSubstationLayoutFactory(); + private ZoneLayoutFactory zoneLayoutFactory = new HorizontalZoneLayoutFactory(); + + public SvgParameters getSvgParameters() { + return svgParameters; + } + + public SldParameters setSvgParameters(SvgParameters svgParameters) { + this.svgParameters = Objects.requireNonNull(svgParameters); + return this; + } + + public LayoutParameters getLayoutParameters() { + return layoutParameters; + } + + public SldParameters setLayoutParameters(LayoutParameters layoutParameters) { + this.layoutParameters = Objects.requireNonNull(layoutParameters); + return this; + } + + public ComponentLibrary getComponentLibrary() { + return componentLibrary; + } + + public SldParameters setComponentLibrary(ComponentLibrary componentLibrary) { + this.componentLibrary = Objects.requireNonNull(componentLibrary); + return this; + } + + public LabelProvider createLabelProvider(Network network) { + return labelProviderFactory.create(network, componentLibrary, layoutParameters, svgParameters); + } + + public SldParameters setLabelProviderFactory(LabelProviderFactory labelProviderFactory) { + this.labelProviderFactory = Objects.requireNonNull(labelProviderFactory); + return this; + } + + public StyleProviderFactory getStyleProviderFactory() { + return styleProviderFactory; + } + + public SldParameters setStyleProviderFactory(StyleProviderFactory styleProviderFactory) { + this.styleProviderFactory = Objects.requireNonNull(styleProviderFactory); + return this; + } + + public VoltageLevelLayoutFactory createVoltageLevelLayoutFactory(Network network) { + return voltageLevelLayoutFactoryCreator.create(network); + } + + public SldParameters setVoltageLevelLayoutFactoryCreator(VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) { + this.voltageLevelLayoutFactoryCreator = Objects.requireNonNull(voltageLevelLayoutFactoryCreator); + return this; + } + + public SubstationLayoutFactory getSubstationLayoutFactory() { + return substationLayoutFactory; + } + + public SldParameters setSubstationLayoutFactory(SubstationLayoutFactory substationLayoutFactory) { + this.substationLayoutFactory = Objects.requireNonNull(substationLayoutFactory); + return this; + } + + public ZoneLayoutFactory getZoneLayoutFactory() { + return zoneLayoutFactory; + } + + public SldParameters setZoneLayoutFactory(ZoneLayoutFactory zoneLayoutFactory) { + this.zoneLayoutFactory = Objects.requireNonNull(zoneLayoutFactory); + return this; + } + +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/SubstationRawBuilder.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/SubstationRawBuilder.java index e2aefdbb1..0075ab7d8 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/SubstationRawBuilder.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/SubstationRawBuilder.java @@ -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.sld.builders; import com.powsybl.commons.*; @@ -15,6 +21,12 @@ import java.util.Map; import java.util.stream.Stream; +/** + * + * @author Florian Dupuy + * @author Benoit Jeanson + */ + public class SubstationRawBuilder extends AbstractRawBuilder { protected static final Logger LOGGER = LoggerFactory.getLogger(SubstationRawBuilder.class); diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/VoltageLevelRawBuilder.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/VoltageLevelRawBuilder.java index fb755441f..ed5d081cf 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/VoltageLevelRawBuilder.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/builders/VoltageLevelRawBuilder.java @@ -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.sld.builders; import com.powsybl.sld.model.coordinate.Direction; @@ -8,6 +14,11 @@ import java.util.function.Function; +/** + * + * @author Florian Dupuy + * @author Benoit Jeanson + */ public class VoltageLevelRawBuilder { private final VoltageLevelInfos voltageLevelInfos; diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java index b80a64dbe..b9fb9b0f0 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java @@ -3,17 +3,20 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.layout; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.powsybl.diagram.util.ValueFormatter; import com.powsybl.sld.library.ComponentSize; import com.powsybl.sld.library.ComponentTypeName; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; /** * @author Benoit Jeanson @@ -26,223 +29,103 @@ public class LayoutParameters { private double verticalSpaceBus = 25; private double horizontalBusPadding = 20; - private double cellWidth = 50; - private double externCellHeight = 250; private double internCellHeight = 40; - private double stackHeight = 30; - - private boolean showGrid = false; - - private boolean showInternalNodes = false; - - private double scaleFactor = 1; - - private String diagramName = null; - - private boolean drawStraightWires = false; - private double horizontalSnakeLinePadding = 20; private double verticalSnakeLinePadding = 25; - private double feederInfosOuterMargin = 20; private double spaceForFeederInfos = 50; - - private boolean avoidSVGComponentsDuplication = false; - private boolean adaptCellHeightToContent = true; private double maxComponentHeight = 12; private double minSpaceBetweenComponents = 15; private double minExternCellHeight = 80; - - private double angleLabelShift = 15.; - private boolean labelCentered = false; - private boolean labelDiagonal = false; - - private boolean tooltipEnabled = false; - - private boolean addNodesInfos = false; - - private boolean feederInfoSymmetry = false; - - private CssLocation cssLocation = CssLocation.INSERTED_IN_SVG; - private Padding voltageLevelPadding = new Padding(20, 60, 20, 60); - private Padding diagramPadding = new Padding(20); - - private boolean svgWidthAndHeightAdded = false; - - private boolean useName = false; - - private double feederInfosIntraMargin = 10; - private Alignment busbarsAlignment = Alignment.FIRST; - + private List componentsOnBusbars = List.of(ComponentTypeName.DISCONNECTOR); // Components which are displayed on busbars private boolean removeFictitiousSwitchNodes = false; - - /** - * Can be used as horizontal shifting value for busInfo indicator. - * Could be negative value. - */ - private double busInfoMargin = 0.0; - - /** Components which are displayed on busbars */ - private List componentsOnBusbars = List.of(ComponentTypeName.DISCONNECTOR); - private String languageTag = "en"; - private int voltageValuePrecision = 1; - private int powerValuePrecision = 0; - private int angleValuePrecision = 1; - private int currentValuePrecision = 0; - - /** em dash unicode for undefined value */ - private String undefinedValueSymbol = "\u2014"; + private double cgmesScaleFactor = 1; + private String cgmesDiagramName = null; + private boolean cgmesUseNames = true; @JsonIgnore private Map componentsSize; - private boolean displayCurrentFeederInfo = false; @JsonCreator public LayoutParameters() { } @JsonCreator - public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLevelPadding, - @JsonProperty("diagramPadding") Padding diagramPadding, - @JsonProperty("verticalSpaceBus") double verticalSpaceBus, + public LayoutParameters(@JsonProperty("verticalSpaceBus") double verticalSpaceBus, @JsonProperty("horizontalBusPadding") double horizontalBusPadding, @JsonProperty("cellWidth") double cellWidth, @JsonProperty("externCellHeight") double externCellHeight, @JsonProperty("internCellHeight") double internCellHeight, @JsonProperty("stackHeight") double stackHeight, - @JsonProperty("showGrid") boolean showGrid, - @JsonProperty("tooltipEnabled") boolean tooltipEnabled, - @JsonProperty("showInternalNodes") boolean showInternalNodes, - @JsonProperty("scaleFactor") double scaleFactor, - @JsonProperty("drawStraightWires") boolean drawStraightWires, @JsonProperty("horizontalSnakeLinePadding") double horizontalSnakeLinePadding, @JsonProperty("verticalSnakeLinePadding") double verticalSnakeLinePadding, - @JsonProperty("feederInfosOuterMargin") double feederInfosOuterMargin, @JsonProperty("spaceForFeederInfos") double spaceForFeederInfos, - @JsonProperty("diagramName") String diagramName, - @JsonProperty("avoidSVGComponentsDuplication") boolean avoidSVGComponentsDuplication, @JsonProperty("adaptCellHeightToContent") boolean adaptCellHeightToContent, @JsonProperty("maxComponentHeight") double maxComponentHeight, @JsonProperty("minSpaceBetweenComponents") double minSpaceBetweenComponents, @JsonProperty("minExternCellHeight") double minExternCellHeight, - @JsonProperty("labelCentered") boolean labelCentered, - @JsonProperty("labelDiagonal") boolean labelDiagonal, - @JsonProperty("angleLabelShift") double angleLabelShift, - @JsonProperty("addNodesInfos") boolean addNodesInfos, - @JsonProperty("feederInfoSymmetry") boolean feederInfoSymmetry, - @JsonProperty("cssLocation") CssLocation cssLocation, - @JsonProperty("svgWidthAndHeightAdded") boolean svgWidthAndHeightAdded, - @JsonProperty("useName") boolean useName, - @JsonProperty("feederInfosIntraMargin") double feederInfosIntraMargin, - @JsonProperty("busInfoMargin") double busInfoMargin, + @JsonProperty("voltageLevelPadding") Padding voltageLevelPadding, + @JsonProperty("diagramPadding") Padding diagramPadding, @JsonProperty("busbarsAlignment") Alignment busbarsAlignment, @JsonProperty("componentsOnBusbars") List componentsOnBusbars, - @JsonProperty("languageTag") String languageTag, - @JsonProperty("voltageValuePrecision") int voltageValuePrecision, - @JsonProperty("powerValuePrecision") int powerValuePrecision, - @JsonProperty("angleValuePrecision") int angleValuePrecision, - @JsonProperty("currentValuePrecision") int currentValuePrecision, - @JsonProperty("displayCurrentFeederInfo") boolean displayCurrentFeederInfo, - @JsonProperty("undefinedValueSymbol") String undefinedValueSymbol, - @JsonProperty("removeFictitiousSwitchNodes") boolean removeFictitiousSwitchNodes) { + @JsonProperty("removeFictitiousSwitchNodes") boolean removeFictitiousSwitchNodes, + @JsonProperty("cgmesScaleFactor") double cgmesScaleFactor, + @JsonProperty("cgmesDiagramName") String cgmesDiagramName, + @JsonProperty("cgmesUseNames") boolean cgmesUseNames) { - this.diagramPadding = diagramPadding; - this.voltageLevelPadding = voltageLevelPadding; this.verticalSpaceBus = verticalSpaceBus; this.horizontalBusPadding = horizontalBusPadding; this.cellWidth = cellWidth; this.externCellHeight = externCellHeight; this.internCellHeight = internCellHeight; this.stackHeight = stackHeight; - this.showGrid = showGrid; - this.tooltipEnabled = tooltipEnabled; - this.showInternalNodes = showInternalNodes; - this.scaleFactor = scaleFactor; - this.drawStraightWires = drawStraightWires; this.horizontalSnakeLinePadding = horizontalSnakeLinePadding; this.verticalSnakeLinePadding = verticalSnakeLinePadding; - this.feederInfosOuterMargin = feederInfosOuterMargin; this.spaceForFeederInfos = spaceForFeederInfos; - this.diagramName = diagramName; - this.avoidSVGComponentsDuplication = avoidSVGComponentsDuplication; this.adaptCellHeightToContent = adaptCellHeightToContent; this.maxComponentHeight = maxComponentHeight; this.minSpaceBetweenComponents = minSpaceBetweenComponents; this.minExternCellHeight = minExternCellHeight; - this.labelCentered = labelCentered; - this.labelDiagonal = labelDiagonal; - this.angleLabelShift = angleLabelShift; - this.addNodesInfos = addNodesInfos; - this.feederInfoSymmetry = feederInfoSymmetry; - this.cssLocation = cssLocation; - this.svgWidthAndHeightAdded = svgWidthAndHeightAdded; - this.useName = useName; - this.feederInfosIntraMargin = feederInfosIntraMargin; - this.busInfoMargin = busInfoMargin; + this.voltageLevelPadding = voltageLevelPadding; + this.diagramPadding = diagramPadding; this.busbarsAlignment = busbarsAlignment; this.componentsOnBusbars = new ArrayList<>(componentsOnBusbars); - this.languageTag = languageTag; - this.voltageValuePrecision = voltageValuePrecision; - this.powerValuePrecision = powerValuePrecision; - this.angleValuePrecision = angleValuePrecision; - this.currentValuePrecision = currentValuePrecision; - this.displayCurrentFeederInfo = displayCurrentFeederInfo; - this.undefinedValueSymbol = undefinedValueSymbol; this.removeFictitiousSwitchNodes = removeFictitiousSwitchNodes; + this.cgmesDiagramName = cgmesDiagramName; + this.cgmesScaleFactor = cgmesScaleFactor; + this.cgmesUseNames = cgmesUseNames; } public LayoutParameters(LayoutParameters other) { Objects.requireNonNull(other); - diagramPadding = new Padding(other.diagramPadding); - voltageLevelPadding = new Padding(other.voltageLevelPadding); verticalSpaceBus = other.verticalSpaceBus; horizontalBusPadding = other.horizontalBusPadding; cellWidth = other.cellWidth; externCellHeight = other.externCellHeight; internCellHeight = other.internCellHeight; stackHeight = other.stackHeight; - showGrid = other.showGrid; - tooltipEnabled = other.tooltipEnabled; - showInternalNodes = other.showInternalNodes; - scaleFactor = other.scaleFactor; - drawStraightWires = other.drawStraightWires; horizontalSnakeLinePadding = other.horizontalSnakeLinePadding; verticalSnakeLinePadding = other.verticalSnakeLinePadding; - feederInfosOuterMargin = other.feederInfosOuterMargin; spaceForFeederInfos = other.spaceForFeederInfos; - diagramName = other.diagramName; - avoidSVGComponentsDuplication = other.avoidSVGComponentsDuplication; adaptCellHeightToContent = other.adaptCellHeightToContent; maxComponentHeight = other.maxComponentHeight; minSpaceBetweenComponents = other.minSpaceBetweenComponents; minExternCellHeight = other.minExternCellHeight; - componentsSize = other.componentsSize; - angleLabelShift = other.angleLabelShift; - labelDiagonal = other.labelDiagonal; - labelCentered = other.labelCentered; - addNodesInfos = other.addNodesInfos; - feederInfoSymmetry = other.feederInfoSymmetry; - cssLocation = other.cssLocation; - svgWidthAndHeightAdded = other.svgWidthAndHeightAdded; - useName = other.useName; - feederInfosIntraMargin = other.feederInfosIntraMargin; - busInfoMargin = other.busInfoMargin; + voltageLevelPadding = new Padding(other.voltageLevelPadding); + diagramPadding = new Padding(other.diagramPadding); busbarsAlignment = other.busbarsAlignment; componentsOnBusbars = new ArrayList<>(other.componentsOnBusbars); - languageTag = other.languageTag; - voltageValuePrecision = other.voltageValuePrecision; - powerValuePrecision = other.powerValuePrecision; - angleValuePrecision = other.angleValuePrecision; - currentValuePrecision = other.currentValuePrecision; - displayCurrentFeederInfo = other.displayCurrentFeederInfo; - undefinedValueSymbol = other.undefinedValueSymbol; removeFictitiousSwitchNodes = other.removeFictitiousSwitchNodes; + componentsSize = other.componentsSize; + cgmesScaleFactor = other.cgmesScaleFactor; + cgmesDiagramName = other.cgmesDiagramName; + cgmesUseNames = other.cgmesUseNames; } public double getVerticalSpaceBus() { @@ -299,51 +182,6 @@ public LayoutParameters setStackHeight(double stackHeight) { return this; } - public boolean isShowGrid() { - return showGrid; - } - - public LayoutParameters setShowGrid(boolean showGrid) { - this.showGrid = showGrid; - return this; - } - - public boolean isShowInternalNodes() { - return showInternalNodes; - } - - public LayoutParameters setShowInternalNodes(boolean showInternalNodes) { - this.showInternalNodes = showInternalNodes; - return this; - } - - public double getScaleFactor() { - return scaleFactor; - } - - public LayoutParameters setScaleFactor(double scaleFactor) { - this.scaleFactor = scaleFactor; - return this; - } - - public String getDiagramName() { - return diagramName; - } - - public LayoutParameters setDiagramName(String diagramName) { - this.diagramName = diagramName; - return this; - } - - public boolean isDrawStraightWires() { - return drawStraightWires; - } - - public LayoutParameters setDrawStraightWires(boolean drawStraightWires) { - this.drawStraightWires = drawStraightWires; - return this; - } - public double getHorizontalSnakeLinePadding() { return horizontalSnakeLinePadding; } @@ -362,21 +200,12 @@ public LayoutParameters setVerticalSnakeLinePadding(double verticalSnakeLinePadd return this; } - public double getFeederInfosOuterMargin() { - return feederInfosOuterMargin; - } - - public LayoutParameters setFeederInfosOuterMargin(double feederInfosOuterMargin) { - this.feederInfosOuterMargin = feederInfosOuterMargin; - return this; - } - - public boolean isAvoidSVGComponentsDuplication() { - return avoidSVGComponentsDuplication; + public double getSpaceForFeederInfos() { + return spaceForFeederInfos; } - public LayoutParameters setAvoidSVGComponentsDuplication(boolean avoidSVGComponentsDuplication) { - this.avoidSVGComponentsDuplication = avoidSVGComponentsDuplication; + public LayoutParameters setSpaceForFeederInfos(double spaceForFeederInfos) { + this.spaceForFeederInfos = spaceForFeederInfos; return this; } @@ -416,86 +245,6 @@ public LayoutParameters setMinExternCellHeight(double minExternCellHeight) { return this; } - public void setComponentsSize(Map componentsSize) { - this.componentsSize = componentsSize; - } - - public Map getComponentsSize() { - return componentsSize; - } - - public double getAngleLabelShift() { - return angleLabelShift; - } - - public LayoutParameters setAngleLabelShift(double angleLabelShift) { - this.angleLabelShift = angleLabelShift; - return this; - } - - public boolean isLabelCentered() { - return labelCentered; - } - - public LayoutParameters setLabelCentered(boolean labelCentered) { - this.labelCentered = labelCentered; - return this; - } - - public boolean isLabelDiagonal() { - return labelDiagonal; - } - - public LayoutParameters setLabelDiagonal(boolean labelDiagonal) { - this.labelDiagonal = labelDiagonal; - return this; - } - - public boolean isTooltipEnabled() { - return tooltipEnabled; - } - - public LayoutParameters setTooltipEnabled(boolean tooltipEnabled) { - this.tooltipEnabled = tooltipEnabled; - return this; - } - - public boolean isAddNodesInfos() { - return addNodesInfos; - } - - public LayoutParameters setAddNodesInfos(boolean addNodesInfos) { - this.addNodesInfos = addNodesInfos; - return this; - } - - public double getSpaceForFeederInfos() { - return spaceForFeederInfos; - } - - public LayoutParameters setSpaceForFeederInfos(double spaceForFeederInfos) { - this.spaceForFeederInfos = spaceForFeederInfos; - return this; - } - - public boolean isFeederInfoSymmetry() { - return feederInfoSymmetry; - } - - public LayoutParameters setFeederInfoSymmetry(boolean feederInfoSymmetry) { - this.feederInfoSymmetry = feederInfoSymmetry; - return this; - } - - public CssLocation getCssLocation() { - return cssLocation; - } - - public LayoutParameters setCssLocation(CssLocation cssLocation) { - this.cssLocation = cssLocation; - return this; - } - public Padding getVoltageLevelPadding() { return voltageLevelPadding; } @@ -514,47 +263,6 @@ public LayoutParameters setDiagrammPadding(double paddingLeft, double paddingTop return this; } - public boolean isSvgWidthAndHeightAdded() { - return svgWidthAndHeightAdded; - } - - public LayoutParameters setSvgWidthAndHeightAdded(boolean svgWidthAndHeightAdded) { - this.svgWidthAndHeightAdded = svgWidthAndHeightAdded; - return this; - } - - @JsonIgnore - public double getBusPadding() { - return getCellWidth() / 4; - } - - public boolean isUseName() { - return useName; - } - - public LayoutParameters setUseName(boolean useName) { - this.useName = useName; - return this; - } - - public double getFeederInfosIntraMargin() { - return feederInfosIntraMargin; - } - - public LayoutParameters setFeederInfosIntraMargin(double feederInfosIntraMargin) { - this.feederInfosIntraMargin = feederInfosIntraMargin; - return this; - } - - public double getBusInfoMargin() { - return busInfoMargin; - } - - public LayoutParameters setBusInfoMargin(double busInfoMargin) { - this.busInfoMargin = busInfoMargin; - return this; - } - public Alignment getBusbarsAlignment() { return busbarsAlignment; } @@ -573,65 +281,52 @@ public LayoutParameters setComponentsOnBusbars(List componentsOnBusbars) return this; } - public String getLanguageTag() { - return languageTag; + public Map getComponentsSize() { + return componentsSize; } - /** - * Sets the language tag string. This is used to format the value displayed according to the corresponding standards. - * @param languageTag Specified IETF BCP 47 language tag string - */ - public LayoutParameters setLanguageTag(String languageTag) { - this.languageTag = languageTag; - return this; + public void setComponentsSize(Map componentsSize) { + this.componentsSize = componentsSize; } - public int getVoltageValuePrecision() { - return voltageValuePrecision; + public boolean isRemoveFictitiousSwitchNodes() { + return removeFictitiousSwitchNodes; } - public LayoutParameters setVoltageValuePrecision(int voltageValuePrecision) { - this.voltageValuePrecision = voltageValuePrecision; + public LayoutParameters setRemoveFictitiousSwitchNodes(boolean removeFictitiousSwitchNodes) { + this.removeFictitiousSwitchNodes = removeFictitiousSwitchNodes; return this; } - public int getPowerValuePrecision() { - return powerValuePrecision; - } - - public LayoutParameters setPowerValuePrecision(int powerValuePrecision) { - this.powerValuePrecision = powerValuePrecision; - return this; + @JsonIgnore + public double getBusPadding() { + return getCellWidth() / 4; } - public int getAngleValuePrecision() { - return angleValuePrecision; + public double getCgmesScaleFactor() { + return cgmesScaleFactor; } - public LayoutParameters setAngleValuePrecision(int angleValuePrecision) { - this.angleValuePrecision = angleValuePrecision; + public LayoutParameters setCgmesScaleFactor(double cgmesScaleFactor) { + this.cgmesScaleFactor = cgmesScaleFactor; return this; } - public int getCurrentValuePrecision() { - return currentValuePrecision; + public String getCgmesDiagramName() { + return cgmesDiagramName; } - public LayoutParameters setCurrentValuePrecision(int currentValuePrecision) { - this.currentValuePrecision = currentValuePrecision; + public LayoutParameters setCgmesDiagramName(String cgmesDiagramName) { + this.cgmesDiagramName = cgmesDiagramName; return this; } - public ValueFormatter createValueFormatter() { - return new ValueFormatter(powerValuePrecision, voltageValuePrecision, currentValuePrecision, angleValuePrecision, Locale.forLanguageTag(languageTag), undefinedValueSymbol); - } - - public boolean isDisplayCurrentFeederInfo() { - return this.displayCurrentFeederInfo; + public boolean isCgmesUseNames() { + return cgmesUseNames; } - public LayoutParameters setDisplayCurrentFeederInfo(boolean displayCurrentFeederInfo) { - this.displayCurrentFeederInfo = displayCurrentFeederInfo; + public LayoutParameters setCgmesUseNames(boolean cgmesUseNames) { + this.cgmesUseNames = cgmesUseNames; return this; } @@ -639,10 +334,6 @@ public enum Alignment { FIRST, LAST, MIDDLE, NONE; } - public enum CssLocation { - INSERTED_IN_SVG, EXTERNAL_IMPORTED, EXTERNAL_NO_IMPORT; - } - public static class Padding { private final double left; private final double top; @@ -692,22 +383,4 @@ public double getFeederSpan() { return getSpaceForFeederInfos() + getMaxComponentHeight(); } - public String getUndefinedValueSymbol() { - return undefinedValueSymbol; - } - - public LayoutParameters setUndefinedValueSymbol(String undefinedValueSymbol) { - this.undefinedValueSymbol = undefinedValueSymbol; - return this; - } - - public boolean isRemoveFictitiousSwitchNodes() { - return removeFictitiousSwitchNodes; - } - - public LayoutParameters setRemoveFictitiousSwitchNodes(boolean removeFictitiousSwitchNodes) { - this.removeFictitiousSwitchNodes = removeFictitiousSwitchNodes; - return this; - } - } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VoltageLevelLayoutFactoryCreator.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VoltageLevelLayoutFactoryCreator.java new file mode 100644 index 000000000..ea7af72e7 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VoltageLevelLayoutFactoryCreator.java @@ -0,0 +1,34 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.sld.layout; + +import com.powsybl.iidm.network.Network; + +/** + * + * @author Sophie Frasnedo + */ + +@FunctionalInterface +public interface VoltageLevelLayoutFactoryCreator { + VoltageLevelLayoutFactory create(Network network); + + static VoltageLevelLayoutFactoryCreator newSmartVoltageLevelLayoutFactoryCreator() { + return SmartVoltageLevelLayoutFactory::new; + } + + static VoltageLevelLayoutFactoryCreator newPositionVoltageLevelLayoutFactoryCreator(PositionFinder positionFinder) { + return i -> new PositionVoltageLevelLayoutFactory(positionFinder); + } + + static VoltageLevelLayoutFactoryCreator newPositionVoltageLevelLayoutFactoryCreator() { + return i -> new PositionVoltageLevelLayoutFactory(); + } + +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/coordinate/Direction.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/coordinate/Direction.java index 15f78d2a3..4e5e7f50e 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/coordinate/Direction.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/coordinate/Direction.java @@ -1,5 +1,15 @@ + +/** + * 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.sld.model.coordinate; +/** + * @author Benoit Jeanson + */ public enum Direction { TOP, BOTTOM, MIDDLE, UNDEFINED; diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/nodes/Node.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/nodes/Node.java index 34e9df53f..09ef68e1c 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/nodes/Node.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/nodes/Node.java @@ -1,3 +1,9 @@ +/** + * Copyright (c) 2019, 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.sld.model.nodes; import com.fasterxml.jackson.core.JsonGenerator; @@ -10,6 +16,13 @@ import java.util.List; import java.util.Optional; +/** + * + * @author Geoffroy Jamgotchian + * @author Franck Lecuyer + * @author Florian Dupuy + * @author Benoit Jeanson + */ public interface Node { enum NodeType { diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/AbstractDiagramLabelProvider.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/AbstractLabelProvider.java similarity index 84% rename from single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/AbstractDiagramLabelProvider.java rename to single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/AbstractLabelProvider.java index 78c1f685f..6bc3e6c53 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/AbstractDiagramLabelProvider.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/AbstractLabelProvider.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -22,7 +23,7 @@ /** * @author Florian Dupuy */ -public abstract class AbstractDiagramLabelProvider implements DiagramLabelProvider { +public abstract class AbstractLabelProvider implements LabelProvider { private static final double LABEL_OFFSET = 5d; private static final double DECORATOR_OFFSET = 5d; @@ -30,11 +31,13 @@ public abstract class AbstractDiagramLabelProvider implements DiagramLabelProvid protected final ComponentLibrary componentLibrary; protected final LayoutParameters layoutParameters; protected final ValueFormatter valueFormatter; + protected final SvgParameters svgParameters; - protected AbstractDiagramLabelProvider(ComponentLibrary componentLibrary, LayoutParameters layoutParameters) { + protected AbstractLabelProvider(ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters) { this.componentLibrary = Objects.requireNonNull(componentLibrary); this.layoutParameters = Objects.requireNonNull(layoutParameters); - this.valueFormatter = layoutParameters.createValueFormatter(); + this.svgParameters = svgParameters; + this.valueFormatter = svgParameters.createValueFormatter(); } @Override @@ -59,7 +62,7 @@ public List getNodeLabels(Node node, Direction direction) { private Optional getLabelOrNameOrId(Node node) { if (node instanceof EquipmentNode) { EquipmentNode eqNode = (EquipmentNode) node; - return Optional.ofNullable(node.getLabel().orElse(layoutParameters.isUseName() ? eqNode.getName() : eqNode.getEquipmentId())); + return Optional.ofNullable(node.getLabel().orElse(svgParameters.isUseName() ? eqNode.getName() : eqNode.getEquipmentId())); } else { return node.getLabel(); } @@ -99,13 +102,13 @@ protected LabelPosition getFeederLabelPosition(Node node, Direction direction) { ? -LABEL_OFFSET : ((int) (componentLibrary.getSize(node.getComponentType()).getHeight()) + LABEL_OFFSET); positionName = direction == TOP ? "N" : "S"; - if (layoutParameters.isLabelDiagonal()) { - angle = direction == TOP ? -layoutParameters.getAngleLabelShift() : layoutParameters.getAngleLabelShift(); + if (svgParameters.isLabelDiagonal()) { + angle = direction == TOP ? -svgParameters.getAngleLabelShift() : svgParameters.getAngleLabelShift(); } } return new LabelPosition(positionName + "_LABEL", - layoutParameters.isLabelCentered() ? 0 : -LABEL_OFFSET, yShift, layoutParameters.isLabelCentered(), (int) angle); + svgParameters.isLabelCentered() ? 0 : -LABEL_OFFSET, yShift, svgParameters.isLabelCentered(), (int) angle); } protected LabelPosition getBusLabelPosition() { diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultLabelProvider.java similarity index 93% rename from single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java rename to single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultLabelProvider.java index e40786c00..49dca67ea 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultLabelProvider.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -16,27 +17,28 @@ import com.powsybl.sld.model.nodes.feeders.FeederTwLeg; import com.powsybl.sld.model.nodes.feeders.FeederWithSides; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; -import static com.powsybl.sld.library.ComponentTypeName.ARROW_ACTIVE; -import static com.powsybl.sld.library.ComponentTypeName.ARROW_CURRENT; -import static com.powsybl.sld.library.ComponentTypeName.ARROW_REACTIVE; +import static com.powsybl.sld.library.ComponentTypeName.*; import static com.powsybl.sld.model.coordinate.Direction.BOTTOM; /** * @author Giovanni Ferrari * @author Franck Lecuyer */ -public class DefaultDiagramLabelProvider extends AbstractDiagramLabelProvider { +public class DefaultLabelProvider extends AbstractLabelProvider { private static final String PLANNED_OUTAGE_BRANCH_NODE_DECORATOR = "LOCK"; private static final String FORCED_OUTAGE_BRANCH_NODE_DECORATOR = "FLASH"; protected final Network network; - public DefaultDiagramLabelProvider(Network net, ComponentLibrary componentLibrary, LayoutParameters layoutParameters) { - super(componentLibrary, layoutParameters); + public DefaultLabelProvider(Network net, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters) { + super(componentLibrary, layoutParameters, svgParameters); this.network = Objects.requireNonNull(net); } @@ -66,7 +68,7 @@ public List getFeederInfos(FeederNode node) { default: break; } - if (node.getDirection() == BOTTOM && !layoutParameters.isFeederInfoSymmetry()) { + if (node.getDirection() == BOTTOM && !svgParameters.isFeederInfoSymmetry()) { Collections.reverse(feederInfos); } return feederInfos; @@ -220,7 +222,7 @@ private List buildFeederInfos(Terminal terminal) { List feederInfoList = new ArrayList<>(); feederInfoList.add(new DirectionalFeederInfo(ARROW_ACTIVE, terminal.getP(), valueFormatter::formatPower)); feederInfoList.add(new DirectionalFeederInfo(ARROW_REACTIVE, terminal.getQ(), valueFormatter::formatPower)); - if (this.layoutParameters.isDisplayCurrentFeederInfo()) { + if (this.svgParameters.isDisplayCurrentFeederInfo()) { feederInfoList.add(new DirectionalFeederInfo(ARROW_CURRENT, terminal.getI(), valueFormatter::formatCurrent)); } return feederInfoList; diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java index a5364d1df..8f94b229f 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -19,12 +20,12 @@ import com.powsybl.sld.model.coordinate.Side; import com.powsybl.sld.model.graphs.*; import com.powsybl.sld.model.nodes.Node; +import com.powsybl.sld.model.nodes.*; import com.powsybl.sld.model.nodes.Node.NodeType; import com.powsybl.sld.model.nodes.feeders.FeederWithSides; -import com.powsybl.sld.model.nodes.*; import com.powsybl.sld.svg.GraphMetadata.FeederInfoMetadata; -import com.powsybl.sld.svg.styles.StyleProvider; import com.powsybl.sld.svg.styles.StyleClassConstants; +import com.powsybl.sld.svg.styles.StyleProvider; import com.powsybl.sld.util.DomUtil; import com.powsybl.sld.util.IdUtil; import org.apache.commons.io.IOUtils; @@ -45,7 +46,8 @@ import static com.powsybl.sld.library.ComponentTypeName.*; import static com.powsybl.sld.model.coordinate.Direction.*; -import static com.powsybl.sld.util.IdUtil.*; +import static com.powsybl.sld.util.IdUtil.escapeClassName; +import static com.powsybl.sld.util.IdUtil.escapeId; /** * @author Benoit Jeanson @@ -81,20 +83,23 @@ public class DefaultSVGWriter implements SVGWriter { protected final LayoutParameters layoutParameters; private final ValueFormatter valueFormatter; + protected final SvgParameters svgParameters; - public DefaultSVGWriter(ComponentLibrary componentLibrary, LayoutParameters layoutParameters) { + public DefaultSVGWriter(ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters) { this.componentLibrary = Objects.requireNonNull(componentLibrary); this.layoutParameters = Objects.requireNonNull(layoutParameters); - this.valueFormatter = layoutParameters.createValueFormatter(); + this.valueFormatter = svgParameters.createValueFormatter(); + this.svgParameters = svgParameters; } /** * Create the SVGDocument corresponding to the graph + * * @param graph zone, voltage level or substation graph * @param writer writer for the SVG content */ @Override - public GraphMetadata write(String prefixId, Graph graph, DiagramLabelProvider labelProvider, StyleProvider styleProvider, Writer writer) { + public GraphMetadata write(Graph graph, LabelProvider labelProvider, StyleProvider styleProvider, Writer writer) { DOMImplementation domImpl = DomUtil.getDocumentBuilder().getDOMImplementation(); Document document = domImpl.createDocument(SVG_NAMESPACE, SVG_QUALIFIED_NAME, null); @@ -109,7 +114,7 @@ public GraphMetadata write(String prefixId, Graph graph, DiagramLabelProvider la createDefsSVGComponents(document, listUsedComponentSVG); addFrame(document); - GraphMetadata metadata = writeGraph(prefixId, graph, document, labelProvider, styleProvider); + GraphMetadata metadata = writeGraph(graph, document, labelProvider, styleProvider); DomUtil.transformDocument(document, writer); @@ -118,7 +123,7 @@ public GraphMetadata write(String prefixId, Graph graph, DiagramLabelProvider la private void setDocumentSize(Graph graph, Document document) { document.getDocumentElement().setAttribute("viewBox", "0 0 " + getDiagramWidth(graph, layoutParameters) + " " + getDiagramHeight(graph, layoutParameters)); - if (layoutParameters.isSvgWidthAndHeightAdded()) { + if (svgParameters.isSvgWidthAndHeightAdded()) { document.getDocumentElement().setAttribute(WIDTH, Double.toString(getDiagramWidth(graph, layoutParameters))); document.getDocumentElement().setAttribute(HEIGHT, Double.toString(getDiagramHeight(graph, layoutParameters))); } @@ -130,25 +135,25 @@ private double getDiagramWidth(Graph graph, LayoutParameters layoutParameters) { private double getDiagramHeight(Graph graph, LayoutParameters layoutParameters) { double height = graph.getHeight() + layoutParameters.getDiagramPadding().getTop() + layoutParameters.getDiagramPadding().getBottom(); - if (graph instanceof VoltageLevelGraph && layoutParameters.isAddNodesInfos()) { + if (graph instanceof VoltageLevelGraph && svgParameters.isAddNodesInfos()) { height += 6 * CIRCLE_RADIUS_NODE_INFOS_SIZE; } return height; } - protected void addStyle(Document document, StyleProvider styleProvider, DiagramLabelProvider labelProvider, + protected void addStyle(Document document, StyleProvider styleProvider, LabelProvider labelProvider, Graph graph, Set listUsedComponentSVG) { graph.getAllNodesStream().forEach(n -> { listUsedComponentSVG.add(n.getComponentType()); - List nodeDecorators = labelProvider.getNodeDecorators(n, graph.getDirection(n)); + List nodeDecorators = labelProvider.getNodeDecorators(n, graph.getDirection(n)); if (nodeDecorators != null) { nodeDecorators.forEach(nodeDecorator -> listUsedComponentSVG.add(nodeDecorator.getType())); } }); Element style = document.createElement(STYLE); - switch (layoutParameters.getCssLocation()) { + switch (svgParameters.getCssLocation()) { case INSERTED_IN_SVG: List urls = styleProvider.getCssUrls(); urls.addAll(componentLibrary.getCssUrls()); @@ -166,7 +171,7 @@ protected void addStyle(Document document, StyleProvider styleProvider, DiagramL // Nothing to do break; default: - throw new AssertionError("Unexpected CSS location: " + layoutParameters.getCssLocation()); + throw new AssertionError("Unexpected CSS location: " + svgParameters.getCssLocation()); } } @@ -202,19 +207,19 @@ private void addFrame(Document document) { /** * Create the SVGDocument corresponding to the graph */ - protected GraphMetadata writeGraph(String prefixId, Graph graph, Document document, DiagramLabelProvider initProvider, StyleProvider styleProvider) { - GraphMetadata metadata = new GraphMetadata(layoutParameters); + protected GraphMetadata writeGraph(Graph graph, Document document, LabelProvider initProvider, StyleProvider styleProvider) { + GraphMetadata metadata = new GraphMetadata(layoutParameters, svgParameters); Element root = document.createElement(GROUP); - drawGrid(prefixId, graph, document, metadata, root); + drawGrid(graph, document, metadata, root); if (graph instanceof VoltageLevelGraph) { - drawVoltageLevel(prefixId, (VoltageLevelGraph) graph, root, metadata, initProvider, styleProvider); + drawVoltageLevel((VoltageLevelGraph) graph, root, metadata, initProvider, styleProvider); } else if (graph instanceof SubstationGraph) { - drawSubstation(prefixId, (SubstationGraph) graph, root, metadata, initProvider, styleProvider); + drawSubstation((SubstationGraph) graph, root, metadata, initProvider, styleProvider); } else if (graph instanceof ZoneGraph) { - drawZone(prefixId, (ZoneGraph) graph, root, metadata, initProvider, styleProvider); + drawZone((ZoneGraph) graph, root, metadata, initProvider, styleProvider); } document.adoptNode(root); @@ -223,56 +228,56 @@ protected GraphMetadata writeGraph(String prefixId, Graph graph, Document docume return metadata; } - private void drawGrid(String prefixId, Graph graph, Document document, GraphMetadata metadata, Element root) { - if (layoutParameters.isShowGrid()) { + private void drawGrid(Graph graph, Document document, GraphMetadata metadata, Element root) { + if (svgParameters.isShowGrid()) { for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { if (vlGraph.isPositionNodeBusesCalculated()) { - drawGrid(prefixId, vlGraph, document, metadata, root); + drawGrid(vlGraph, document, metadata, root); } } } } - protected void drawVoltageLevel(String prefixId, - VoltageLevelGraph graph, + protected void drawVoltageLevel(VoltageLevelGraph graph, Element root, GraphMetadata metadata, - DiagramLabelProvider initProvider, + LabelProvider initProvider, StyleProvider styleProvider) { if (!graph.isForVoltageLevelDiagram()) { - drawGraphLabel(prefixId, root, graph, metadata); + drawGraphLabel(root, graph, metadata); } Set remainingNodesToDraw = graph.getNodeSet(); Set remainingEdgesToDraw = graph.getEdgeSet(); - drawBuses(prefixId, root, graph, metadata, initProvider, styleProvider, remainingNodesToDraw); + drawBuses(root, graph, metadata, initProvider, styleProvider, remainingNodesToDraw); graph.getCellStream().forEach(cell -> - drawCell(prefixId, root, graph, cell, metadata, initProvider, styleProvider, + drawCell(root, graph, cell, metadata, initProvider, styleProvider, remainingEdgesToDraw, remainingNodesToDraw)); - drawEdges(prefixId, root, graph, metadata, initProvider, styleProvider, remainingEdgesToDraw); + drawEdges(root, graph, metadata, initProvider, styleProvider, remainingEdgesToDraw); - drawNodes(prefixId, root, graph, graph.getCoord(), metadata, initProvider, styleProvider, remainingNodesToDraw); + drawNodes(root, graph, graph.getCoord(), metadata, initProvider, styleProvider, remainingNodesToDraw); // Drawing the snake lines before multi-terminal nodes to hide the 3WT connections - drawSnakeLines(prefixId, root, graph, metadata, styleProvider); + drawSnakeLines(root, graph, metadata, styleProvider); // Drawing the nodes outside the voltageLevel graphs (multi-terminal nodes) - drawNodes(prefixId, root, graph, new Point(0, 0), metadata, initProvider, styleProvider, graph.getMultiTermNodes()); + drawNodes(root, graph, new Point(0, 0), metadata, initProvider, styleProvider, graph.getMultiTermNodes()); - if (graph.isForVoltageLevelDiagram() && layoutParameters.isAddNodesInfos()) { - drawNodesInfos(prefixId, root, graph, metadata, initProvider, styleProvider); + if (graph.isForVoltageLevelDiagram() && svgParameters.isAddNodesInfos()) { + drawNodesInfos(root, graph, metadata, initProvider, styleProvider); } } - private void drawCell(String prefixId, Element root, VoltageLevelGraph graph, Cell cell, - GraphMetadata metadata, DiagramLabelProvider initProvider, StyleProvider styleProvider, + private void drawCell(Element root, VoltageLevelGraph graph, Cell cell, + GraphMetadata metadata, LabelProvider initProvider, StyleProvider styleProvider, Set remainingEdgesToDraw, Set remainingNodesToDraw) { // To avoid overlapping lines over the switches, first, we draw all nodes except the switch nodes and bus connections, // then we draw all the edges, and finally we draw the switch nodes and bus connections + String prefixId = metadata.getSvgParameters().getPrefixId(); String cellId = IdUtil.escapeId(prefixId + cell.getId()); Element g = root.getOwnerDocument().createElement(GROUP); @@ -285,8 +290,8 @@ private void drawCell(String prefixId, Element root, VoltageLevelGraph graph, Ce .filter(e -> cellNodes.contains(e.getNode1()) && cellNodes.contains(e.getNode2())) .collect(Collectors.toCollection(LinkedHashSet::new)); - drawEdges(prefixId, g, graph, metadata, initProvider, styleProvider, edgesToDraw); - drawNodes(prefixId, g, graph, graph.getCoord(), metadata, initProvider, styleProvider, nodesToDraw); + drawEdges(g, graph, metadata, initProvider, styleProvider, edgesToDraw); + drawNodes(g, graph, graph.getCoord(), metadata, initProvider, styleProvider, nodesToDraw); remainingEdgesToDraw.removeAll(edgesToDraw); remainingNodesToDraw.removeAll(nodesToDraw); @@ -294,32 +299,32 @@ private void drawCell(String prefixId, Element root, VoltageLevelGraph graph, Ce root.appendChild(g); } - protected void drawSubstation(String prefixId, - SubstationGraph graph, + protected void drawSubstation(SubstationGraph graph, Element root, GraphMetadata metadata, - DiagramLabelProvider initProvider, + LabelProvider initProvider, StyleProvider styleProvider) { // Drawing the voltageLevel graphs for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { - drawVoltageLevel(prefixId, vlGraph, root, metadata, initProvider, styleProvider); + drawVoltageLevel(vlGraph, root, metadata, initProvider, styleProvider); } // Drawing the snake lines before multi-terminal nodes to hide the 3WT connections - drawSnakeLines(prefixId, root, graph, metadata, styleProvider); + drawSnakeLines(root, graph, metadata, styleProvider); // Drawing the nodes outside the voltageLevel graphs (multi-terminal nodes) - drawNodes(prefixId, root, graph, new Point(0, 0), metadata, initProvider, styleProvider, graph.getMultiTermNodes()); + drawNodes(root, graph, new Point(0, 0), metadata, initProvider, styleProvider, graph.getMultiTermNodes()); } /* * Drawing the grid lines (if required) */ - protected void drawGrid(String prefixId, VoltageLevelGraph graph, Document document, GraphMetadata metadata, Element root) { + protected void drawGrid(VoltageLevelGraph graph, Document document, GraphMetadata metadata, Element root) { int maxH = graph.getMaxH(); int maxV = graph.getMaxV(); Element gridRoot = document.createElement(GROUP); + String prefixId = metadata.getSvgParameters().getPrefixId(); String gridId = prefixId + "GRID_" + graph.getVoltageLevelInfos().getId(); gridRoot.setAttribute("id", gridId); @@ -386,24 +391,25 @@ protected void drawGridLine(Document document, double x1, double y1, double x2, /* * Drawing the voltageLevel graph nodes */ - protected void drawBuses(String prefixId, - Element root, + protected void drawBuses(Element root, VoltageLevelGraph graph, GraphMetadata metadata, - DiagramLabelProvider initProvider, + LabelProvider initProvider, StyleProvider styleProvider, Set remainingNodesToDraw) { + String prefixId = metadata.getSvgParameters().getPrefixId(); + for (BusNode busNode : graph.getNodeBuses()) { String nodeId = IdUtil.escapeId(prefixId + busNode.getId()); Element g = root.getOwnerDocument().createElement(GROUP); g.setAttribute("id", nodeId); - g.setAttribute(CLASS, String.join(" ", styleProvider.getNodeStyles(graph, busNode, componentLibrary, layoutParameters.isShowInternalNodes()))); + g.setAttribute(CLASS, String.join(" ", styleProvider.getNodeStyles(graph, busNode, componentLibrary, svgParameters.isShowInternalNodes()))); drawBus(graph, busNode, g); - List nodeLabels = initProvider.getNodeLabels(busNode, graph.getDirection(busNode)); + List nodeLabels = initProvider.getNodeLabels(busNode, graph.getDirection(busNode)); drawNodeLabel(prefixId, g, busNode, nodeLabels); drawNodeDecorators(prefixId, g, graph, busNode, initProvider, styleProvider); @@ -425,9 +431,9 @@ protected void drawBuses(String prefixId, } } - protected List createNodeLabelMetadata(String prefixId, Node node, List nodeLabels) { + protected List createNodeLabelMetadata(String prefixId, Node node, List nodeLabels) { List labelsMetadata = new ArrayList<>(); - for (DiagramLabelProvider.NodeLabel nodeLabel : nodeLabels) { + for (LabelProvider.NodeLabel nodeLabel : nodeLabels) { LabelPosition labelPosition = nodeLabel.getPosition(); String svgId = getNodeLabelId(prefixId, node, labelPosition); labelsMetadata.add(new GraphMetadata.NodeLabelMetadata(svgId, labelPosition.getPositionName(), nodeLabel.getUserDefinedId())); @@ -438,34 +444,35 @@ protected List createNodeLabelMetadata(String p /* * Drawing the voltageLevel graph nodes */ - protected void drawNodes(String prefixId, - Element root, + protected void drawNodes(Element root, BaseGraph graph, Point shift, GraphMetadata metadata, - DiagramLabelProvider labelProvider, + LabelProvider labelProvider, StyleProvider styleProvider, Collection nodes) { + String prefixId = metadata.getSvgParameters().getPrefixId(); + for (Node node : nodes) { String nodeEscapedId = IdUtil.escapeId(prefixId + node.getId()); Element g = root.getOwnerDocument().createElement(GROUP); g.setAttribute("id", nodeEscapedId); - g.setAttribute(CLASS, String.join(" ", styleProvider.getNodeStyles(graph.getVoltageLevelGraph(node), node, componentLibrary, layoutParameters.isShowInternalNodes()))); + g.setAttribute(CLASS, String.join(" ", styleProvider.getNodeStyles(graph.getVoltageLevelGraph(node), node, componentLibrary, svgParameters.isShowInternalNodes()))); incorporateComponents(prefixId, graph, node, shift, g, labelProvider, styleProvider); - List nodeLabels = labelProvider.getNodeLabels(node, graph.getDirection(node)); + List nodeLabels = labelProvider.getNodeLabels(node, graph.getDirection(node)); drawNodeLabel(prefixId, g, node, nodeLabels); drawNodeDecorators(prefixId, g, graph, node, labelProvider, styleProvider); root.appendChild(g); Direction direction = node instanceof FeederNode ? graph.getDirection(node) : Direction.UNDEFINED; - setMetadata(prefixId, metadata, node, nodeEscapedId, graph, direction, nodeLabels); + setMetadata(metadata, node, nodeEscapedId, graph, direction, nodeLabels); } } - protected void setMetadata(String prefixId, GraphMetadata metadata, Node node, String nodeEscapedId, BaseGraph graph, Direction direction, List nodeLabels) { + protected void setMetadata(GraphMetadata metadata, Node node, String nodeEscapedId, BaseGraph graph, Direction direction, List nodeLabels) { String nextVId = null; if (node instanceof FeederNode && ((FeederNode) node).getFeeder() instanceof FeederWithSides) { FeederWithSides feederWs = (FeederWithSides) ((FeederNode) node).getFeeder(); @@ -475,7 +482,10 @@ protected void setMetadata(String prefixId, GraphMetadata metadata, Node node, S } } + String prefixId = metadata.getSvgParameters().getPrefixId(); + String vId = graph instanceof VoltageLevelGraph ? ((VoltageLevelGraph) graph).getVoltageLevelInfos().getId() : ""; + boolean isOpen = node.getType() == NodeType.SWITCH && ((SwitchNode) node).isOpen(); metadata.addNodeMetadata( @@ -495,8 +505,9 @@ private String getUnescapedId(Node node) { return unescapedId; } - protected void drawNodeLabel(String prefixId, Element g, Node node, List nodeLabels) { - for (DiagramLabelProvider.NodeLabel nodeLabel : nodeLabels) { + protected void drawNodeLabel(String prefixId, Element g, Node node, List nodeLabels) { + for (LabelProvider.NodeLabel nodeLabel : nodeLabels) { + LabelPosition labelPosition = nodeLabel.getPosition(); Element label = createLabelElement(nodeLabel.getLabel(), labelPosition.getdX(), labelPosition.getdY(), labelPosition.getShiftAngle(), g); String svgId = getNodeLabelId(prefixId, node, labelPosition); @@ -508,9 +519,9 @@ protected void drawNodeLabel(String prefixId, Element g, Node node, List elementAttributesSetter = (elt, subComponent) -> setComponentAttributes(prefixId, g, graph, node, styleProvider, elt, componentType, subComponent); - String tooltipContent = layoutParameters.isTooltipEnabled() ? labelProvider.getTooltip(node) : null; + String tooltipContent = svgParameters.isTooltipEnabled() ? labelProvider.getTooltip(node) : null; insertSVGIntoDocumentSVG(componentType, g, tooltipContent, elementAttributesSetter); } @@ -620,7 +631,7 @@ private void setInfoAttributes(String infoType, String prefixId, Element g, Elem } } - protected void insertDecoratorSVGIntoDocumentSVG(String prefixId, DiagramLabelProvider.NodeDecorator nodeDecorator, + protected void insertDecoratorSVGIntoDocumentSVG(String prefixId, LabelProvider.NodeDecorator nodeDecorator, Element g, Graph graph, Node node, StyleProvider styleProvider) { BiConsumer elementAttributesSetter = (elt, subComponent) -> setDecoratorAttributes(prefixId, g, graph, node, nodeDecorator, styleProvider, elt, subComponent); @@ -632,7 +643,7 @@ protected void insertSVGIntoDocumentSVG(String componentType, Element g, String BiConsumer elementAttributesSetter) { addToolTip(g, tooltip); Map> subComponents = componentLibrary.getSvgElements(componentType); - subComponents.forEach(layoutParameters.isAvoidSVGComponentsDuplication() ? + subComponents.forEach(svgParameters.isAvoidSVGComponentsDuplication() ? (subComponentName, svgSubComponent) -> insertSubcomponentReference(g, elementAttributesSetter, componentType, subComponentName, subComponents.size()) : (subComponentName, svgSubComponent) -> insertDuplicatedSubcomponent(g, elementAttributesSetter, subComponentName, svgSubComponent) ); @@ -708,7 +719,7 @@ private void setComponentAttributes(String prefixId, Element g, Graph graph, Nod } } - private void setDecoratorAttributes(String prefixId, Element g, Graph graph, Node node, DiagramLabelProvider.NodeDecorator nodeDecorator, + private void setDecoratorAttributes(String prefixId, Element g, Graph graph, Node node, LabelProvider.NodeDecorator nodeDecorator, StyleProvider styleProvider, Element elt, String subComponentName) { replaceId(g, elt, prefixId); ComponentSize decoratorSize = componentLibrary.getSize(nodeDecorator.getType()); @@ -785,8 +796,8 @@ protected void transformFeederInfo(List points, ComponentSize componentSi double cosAngle = dx / distancePoints; double sinAngle = dy / distancePoints; - double x = pointA.getX() + cosAngle * (layoutParameters.getFeederInfosOuterMargin() + shift); - double y = pointA.getY() + sinAngle * (layoutParameters.getFeederInfosOuterMargin() + shift); + double x = pointA.getX() + cosAngle * (svgParameters.getFeederInfosOuterMargin() + shift); + double y = pointA.getY() + sinAngle * (svgParameters.getFeederInfosOuterMargin() + shift); double feederInfoRotationAngle = Math.atan(dy / dx) - Math.PI / 2; if (feederInfoRotationAngle < -Math.PI / 2) { @@ -839,7 +850,7 @@ protected void insertFeederInfos(String prefixId, VoltageLevelGraph graph, FeederNode feederNode, GraphMetadata metadata, - DiagramLabelProvider labelProvider, + LabelProvider labelProvider, StyleProvider styleProvider) { if (points.isEmpty()) { points.add(graph.getShiftedPoint(feederNode)); @@ -852,7 +863,7 @@ protected void insertFeederInfos(String prefixId, addInfoComponentMetadata(metadata, feederInfo.getComponentType()); double height = componentLibrary.getSize(feederInfo.getComponentType()).getHeight(); - shiftFeederInfo += layoutParameters.getFeederInfosIntraMargin() + height; + shiftFeederInfo += svgParameters.getFeederInfosIntraMargin() + height; } } @@ -911,7 +922,7 @@ private void drawFeederInfo(String prefixId, FeederNode feederNode, List } protected void insertBusInfo(String prefixId, Element root, BusNode busNode, - GraphMetadata metadata, DiagramLabelProvider labelProvider, StyleProvider styleProvider) { + GraphMetadata metadata, LabelProvider labelProvider, StyleProvider styleProvider) { Optional busInfo = labelProvider.getBusInfo(busNode); busInfo.ifPresent(info -> { drawBusInfo(prefixId, busNode, root, info, styleProvider, metadata); @@ -925,7 +936,7 @@ private void drawBusInfo(String prefixId, BusNode busNode, Element root, BusInfo // Position ComponentSize size = componentLibrary.getSize(busInfo.getComponentType()); - double shiftX = layoutParameters.getBusInfoMargin(); + double shiftX = svgParameters.getBusInfoMargin(); double dy = -size.getHeight() / 2; double dx = busInfo.getAnchor() == Side.RIGHT ? busNode.getPxWidth() - shiftX - size.getWidth() : shiftX; g.setAttribute(TRANSFORM, TRANSLATE + "(" + dx + "," + dy + ")"); @@ -977,9 +988,10 @@ private static String getNodeLabelId(String prefixId, Node node, LabelPosition l /* * Drawing the voltageLevel graph edges */ - protected void drawEdges(String prefixId, Element root, VoltageLevelGraph graph, GraphMetadata metadata, - DiagramLabelProvider initProvider, StyleProvider styleProvider, Collection edges) { + protected void drawEdges(Element root, VoltageLevelGraph graph, GraphMetadata metadata, + LabelProvider initProvider, StyleProvider styleProvider, Collection edges) { String voltageLevelId = graph.getVoltageLevelInfos().getId(); + String prefixId = metadata.getSvgParameters().getPrefixId(); for (Edge edge : edges) { String wireId = getWireId(prefixId, voltageLevelId, edge); @@ -989,7 +1001,7 @@ protected void drawEdges(String prefixId, Element root, VoltageLevelGraph graph, // Determine points of the polyline Point shift = graph.getCoord(); pol = WireConnection.searchBestAnchorPoints(componentLibrary, graph, edge.getNode1(), edge.getNode2()) - .calculatePolylinePoints(edge.getNode1(), edge.getNode2(), layoutParameters.isDrawStraightWires(), shift); + .calculatePolylinePoints(edge.getNode1(), edge.getNode2(), svgParameters.isDrawStraightWires(), shift); if (!pol.isEmpty()) { Element g = root.getOwnerDocument().createElement(GROUP); @@ -1009,7 +1021,7 @@ protected void drawEdges(String prefixId, Element root, VoltageLevelGraph graph, metadata.addWireMetadata(new GraphMetadata.WireMetadata(wireId, escapeId(edge.getNode1().getId()), escapeId(edge.getNode2().getId()), - layoutParameters.isDrawStraightWires(), + svgParameters.isDrawStraightWires(), false)); if (edge.getNode1() instanceof FeederNode) { @@ -1026,30 +1038,30 @@ protected void drawEdges(String prefixId, Element root, VoltageLevelGraph graph, /* * Drawing the zone graph edges (snakelines between station diagram) */ - protected void drawSnakeLines(String prefixId, Element root, ZoneGraph graph, + protected void drawSnakeLines(Element root, ZoneGraph graph, GraphMetadata metadata, StyleProvider styleProvider) { for (BranchEdge edge : graph.getLineEdges()) { - drawSnakeLines(graph, edge, prefixId, root, metadata, styleProvider); + drawSnakeLines(graph, edge, root, metadata, styleProvider); } } /* * Drawing the substation graph edges (snakelines between voltageLevel diagram) */ - protected void drawSnakeLines(String prefixId, Element root, BaseGraph graph, + protected void drawSnakeLines(Element root, BaseGraph graph, GraphMetadata metadata, StyleProvider styleProvider) { for (BranchEdge edge : graph.getLineEdges()) { - drawSnakeLines(graph, edge, prefixId, root, metadata, styleProvider); + drawSnakeLines(graph, edge, root, metadata, styleProvider); } for (BranchEdge edge : graph.getTwtEdges()) { - drawSnakeLines(graph, edge, prefixId, root, metadata, styleProvider); + drawSnakeLines(graph, edge, root, metadata, styleProvider); } } - private void drawSnakeLines(Graph graph, BranchEdge edge, String prefixId, Element root, GraphMetadata metadata, StyleProvider styleProvider) { + private void drawSnakeLines(Graph graph, BranchEdge edge, Element root, GraphMetadata metadata, StyleProvider styleProvider) { Element g = root.getOwnerDocument().createElement(GROUP); - String snakeLineId = escapeId(prefixId + edge.getId()); + String snakeLineId = escapeId(metadata.getSvgParameters().getPrefixId() + edge.getId()); g.setAttribute("id", snakeLineId); List wireStyles = styleProvider.getEdgeStyles(graph, edge); g.setAttribute(CLASS, String.join(" ", wireStyles)); @@ -1071,7 +1083,7 @@ private void drawSnakeLines(Graph graph, BranchEdge edge, String prefixId, Eleme metadata.addWireMetadata(new GraphMetadata.WireMetadata(snakeLineId, escapeId(edge.getNode1().getId()), escapeId(edge.getNode2().getId()), - layoutParameters.isDrawStraightWires(), + svgParameters.isDrawStraightWires(), true)); } @@ -1104,7 +1116,7 @@ protected String pointsListToString(List polyline) { * Creation of the defs area for the SVG components */ protected void createDefsSVGComponents(Document document, Set listUsedComponentSVG) { - if (layoutParameters.isAvoidSVGComponentsDuplication()) { + if (svgParameters.isAvoidSVGComponentsDuplication()) { // adding also arrows listUsedComponentSVG.add(ARROW_ACTIVE); listUsedComponentSVG.add(ARROW_REACTIVE); @@ -1151,17 +1163,16 @@ private void addSvgSubComponentsToElement(List subComponentElements, El } } - private void drawZone(String prefixId, - ZoneGraph graph, + private void drawZone(ZoneGraph graph, Element root, GraphMetadata metadata, - DiagramLabelProvider initProvider, + LabelProvider initProvider, StyleProvider styleProvider) { for (SubstationGraph sGraph : graph.getSubstations()) { - drawSubstation(prefixId, sGraph, root, metadata, initProvider, styleProvider); + drawSubstation(sGraph, root, metadata, initProvider, styleProvider); } - drawSnakeLines(prefixId, root, graph, metadata, styleProvider); + drawSnakeLines(root, graph, metadata, styleProvider); } /* @@ -1204,8 +1215,8 @@ private void drawNodeInfos(ElectricalNodeInfo nodeInfo, double xShift, double yS g.appendChild(labelAngle); } - private void drawNodesInfos(String prefixId, Element root, VoltageLevelGraph graph, - GraphMetadata metadata, DiagramLabelProvider initProvider, StyleProvider styleProvider) { + private void drawNodesInfos(Element root, VoltageLevelGraph graph, + GraphMetadata metadata, LabelProvider initProvider, StyleProvider styleProvider) { Element nodesInfosNode = root.getOwnerDocument().createElement(GROUP); root.appendChild(nodesInfosNode); @@ -1216,7 +1227,7 @@ private void drawNodesInfos(String prefixId, Element root, VoltageLevelGraph gra double xShift = graph.getX() + xInitPos; for (ElectricalNodeInfo node : initProvider.getElectricalNodesInfos(graph)) { - String idNode = prefixId + "NODE_" + node.getBusId(); + String idNode = metadata.getSvgParameters().getPrefixId() + "NODE_" + node.getBusId(); Element gNode = nodesInfosNode.getOwnerDocument().createElement(GROUP); gNode.setAttribute("id", idNode); diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java index 44fe38124..bc91eff29 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DirectionalFeederInfo.java @@ -1,3 +1,10 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ package com.powsybl.sld.svg; import java.util.Objects; @@ -11,15 +18,15 @@ */ public class DirectionalFeederInfo extends AbstractFeederInfo { - private final DiagramLabelProvider.LabelDirection arrowDirection; + private final LabelProvider.LabelDirection arrowDirection; private final double value; - public DirectionalFeederInfo(String componentType, DiagramLabelProvider.LabelDirection arrowDirection, String leftLabel, String rightLabel) { + public DirectionalFeederInfo(String componentType, LabelProvider.LabelDirection arrowDirection, String leftLabel, String rightLabel) { this(componentType, arrowDirection, leftLabel, rightLabel, null); } - public DirectionalFeederInfo(String componentType, DiagramLabelProvider.LabelDirection arrowDirection, String leftLabel, String rightLabel, String userDefinedId) { + public DirectionalFeederInfo(String componentType, LabelProvider.LabelDirection arrowDirection, String leftLabel, String rightLabel, String userDefinedId) { super(componentType, leftLabel, rightLabel, userDefinedId); this.arrowDirection = Objects.requireNonNull(arrowDirection); this.value = Double.NaN; @@ -35,11 +42,11 @@ public DirectionalFeederInfo(String componentType, double value, DoubleFunction< this.value = value; } - private static DiagramLabelProvider.LabelDirection getArrowDirection(double value) { - return value > 0 ? DiagramLabelProvider.LabelDirection.OUT : DiagramLabelProvider.LabelDirection.IN; + private static LabelProvider.LabelDirection getArrowDirection(double value) { + return value > 0 ? LabelProvider.LabelDirection.OUT : LabelProvider.LabelDirection.IN; } - public DiagramLabelProvider.LabelDirection getDirection() { + public LabelProvider.LabelDirection getDirection() { return arrowDirection; } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java index 6899de440..b8446b217 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -351,6 +352,7 @@ public String getUserDefinedId() { private final Map lineMetadataMap = new HashMap<>(); private final LayoutParameters layoutParameters; + private final SvgParameters svgParameters; private final Map feederInfoMetadataMap = new HashMap<>(); @@ -358,8 +360,8 @@ public String getUserDefinedId() { private final Map busInfoMetadataMap = new HashMap<>(); - public GraphMetadata(LayoutParameters layoutParameters) { - this(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), layoutParameters); + public GraphMetadata(LayoutParameters layoutParameters, SvgParameters svgParameters) { + this(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), layoutParameters, svgParameters); } @JsonCreator @@ -370,7 +372,8 @@ public GraphMetadata(@JsonProperty("components") List componentList, @JsonProperty("feederInfos") List feederInfoMetadataList, @JsonProperty("electricalNodeInfos") List electricalNodeInfoMetadataList, @JsonProperty("busInfos") List busInfoMetadataList, - @JsonProperty("layoutParams") LayoutParameters layoutParams) { + @JsonProperty("layoutParams") LayoutParameters layoutParams, + @JsonProperty("svgParams") SvgParameters svgParams) { for (Component component : componentList) { addComponent(component); } @@ -393,6 +396,7 @@ public GraphMetadata(@JsonProperty("components") List componentList, addBusInfoMetadata(busInfoMetadata); } layoutParameters = layoutParams; + svgParameters = svgParams; } public static GraphMetadata parseJson(Path file) { @@ -558,4 +562,10 @@ public LayoutParameters getLayoutParameters() { return layoutParameters; } + + @JsonProperty("svgParams") + public SvgParameters getSvgParameters() { + return svgParameters; + + } } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DiagramLabelProvider.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/LabelProvider.java similarity index 94% rename from single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DiagramLabelProvider.java rename to single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/LabelProvider.java index adb72c679..dde6d5825 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DiagramLabelProvider.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/LabelProvider.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -13,13 +14,15 @@ import com.powsybl.sld.model.nodes.FeederNode; import com.powsybl.sld.model.nodes.Node; -import java.util.*; +import java.util.List; +import java.util.Map; +import java.util.Optional; /** * @author Giovanni Ferrari * @author Franck Lecuyer */ -public interface DiagramLabelProvider { +public interface LabelProvider { class NodeLabel { private final String label; diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/LabelProviderFactory.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/LabelProviderFactory.java new file mode 100644 index 000000000..437f55c22 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/LabelProviderFactory.java @@ -0,0 +1,22 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.sld.svg; + +import com.powsybl.iidm.network.Network; +import com.powsybl.sld.layout.LayoutParameters; +import com.powsybl.sld.library.ComponentLibrary; + +/** + * + * @author Sophie Frasnedo + */ + +@FunctionalInterface +public interface LabelProviderFactory { + LabelProvider create(Network network, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters); +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/SVGWriter.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/SVGWriter.java index b784b6767..91e8338cb 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/SVGWriter.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/SVGWriter.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -16,5 +17,5 @@ * @author Franck Lecuyer */ public interface SVGWriter { - GraphMetadata write(String prefixId, Graph graph, DiagramLabelProvider initProvider, StyleProvider styleProvider, Writer writer); + GraphMetadata write(Graph graph, LabelProvider initProvider, StyleProvider styleProvider, Writer writer); } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/SvgParameters.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/SvgParameters.java new file mode 100644 index 000000000..b86a9fa66 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/SvgParameters.java @@ -0,0 +1,319 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.sld.svg; + +import com.powsybl.diagram.util.ValueFormatter; + +import java.util.Locale; +import java.util.Objects; + +/** + * + * @author Sophie Frasnedo + */ +public class SvgParameters { + + private String prefixId = ""; + private String undefinedValueSymbol = "\u2014"; //em dash unicode for undefined value + private String languageTag = "en"; + private int voltageValuePrecision = 1; + private int powerValuePrecision = 0; + private int angleValuePrecision = 1; + private int currentValuePrecision = 0; + private double busInfoMargin = 0.0; //Can be used as horizontal shifting value for busInfo indicator. Can be negative value + private double feederInfosIntraMargin = 10; + private double feederInfosOuterMargin = 20; + private boolean feederInfoSymmetry = false; + private boolean addNodesInfos = false; + private boolean useName = false; + private double angleLabelShift = 15.; + private boolean labelCentered = false; + private boolean labelDiagonal = false; + private boolean tooltipEnabled = false; + private boolean svgWidthAndHeightAdded = false; + private SvgParameters.CssLocation cssLocation = SvgParameters.CssLocation.INSERTED_IN_SVG; + private boolean avoidSVGComponentsDuplication = false; + private String diagramName = null; + private boolean drawStraightWires = false; + private boolean showGrid = false; + private boolean showInternalNodes = false; + private boolean displayCurrentFeederInfo = false; + + public SvgParameters() { + } + + public enum CssLocation { + INSERTED_IN_SVG, EXTERNAL_IMPORTED, EXTERNAL_NO_IMPORT + } + + public SvgParameters(SvgParameters other) { + Objects.requireNonNull(other); + this.prefixId = other.prefixId; + this.undefinedValueSymbol = other.undefinedValueSymbol; + this.languageTag = other.languageTag; + this.voltageValuePrecision = other.voltageValuePrecision; + this.powerValuePrecision = other.powerValuePrecision; + this.angleValuePrecision = other.angleValuePrecision; + this.currentValuePrecision = other.currentValuePrecision; + this.busInfoMargin = other.busInfoMargin; + this.feederInfosIntraMargin = other.feederInfosIntraMargin; + this.feederInfosOuterMargin = other.feederInfosOuterMargin; + this.feederInfoSymmetry = other.feederInfoSymmetry; + this.addNodesInfos = other.addNodesInfos; + this.useName = other.useName; + this.angleLabelShift = other.angleLabelShift; + this.labelCentered = other.labelCentered; + this.labelDiagonal = other.labelDiagonal; + this.tooltipEnabled = other.tooltipEnabled; + this.svgWidthAndHeightAdded = other.svgWidthAndHeightAdded; + this.cssLocation = other.cssLocation; + this.avoidSVGComponentsDuplication = other.avoidSVGComponentsDuplication; + this.diagramName = other.diagramName; + this.drawStraightWires = other.drawStraightWires; + this.showGrid = other.showGrid; + this.showInternalNodes = other.showInternalNodes; + this.displayCurrentFeederInfo = other.displayCurrentFeederInfo; + } + + public ValueFormatter createValueFormatter() { + return new ValueFormatter(powerValuePrecision, voltageValuePrecision, currentValuePrecision, angleValuePrecision, Locale.forLanguageTag(languageTag), undefinedValueSymbol); + } + + public String getPrefixId() { + return prefixId; + } + + public SvgParameters setPrefixId(String prefixId) { + Objects.requireNonNull(prefixId); + this.prefixId = prefixId; + return this; + } + + public String getUndefinedValueSymbol() { + return undefinedValueSymbol; + } + + public SvgParameters setUndefinedValueSymbol(String undefinedValueSymbol) { + Objects.requireNonNull(undefinedValueSymbol); + this.undefinedValueSymbol = undefinedValueSymbol; + return this; + } + + public String getLanguageTag() { + return languageTag; + } + + /** + * Sets the language tag string. This is used to format the value displayed according to the corresponding standards. + * @param languageTag Specified IETF BCP 47 language tag string + */ + public SvgParameters setLanguageTag(String languageTag) { + Objects.requireNonNull(languageTag); + this.languageTag = languageTag; + return this; + } + + public int getVoltageValuePrecision() { + return voltageValuePrecision; + } + + public SvgParameters setVoltageValuePrecision(int voltageValuePrecision) { + this.voltageValuePrecision = voltageValuePrecision; + return this; + } + + public int getPowerValuePrecision() { + return powerValuePrecision; + } + + public SvgParameters setPowerValuePrecision(int powerValuePrecision) { + this.powerValuePrecision = powerValuePrecision; + return this; + } + + public int getAngleValuePrecision() { + return angleValuePrecision; + } + + public SvgParameters setAngleValuePrecision(int angleValuePrecision) { + this.angleValuePrecision = angleValuePrecision; + return this; + } + + public int getCurrentValuePrecision() { + return currentValuePrecision; + } + + public SvgParameters setCurrentValuePrecision(int currentValuePrecision) { + this.currentValuePrecision = currentValuePrecision; + return this; + } + + public double getBusInfoMargin() { + return busInfoMargin; + } + + public SvgParameters setBusInfoMargin(double busInfoMargin) { + this.busInfoMargin = busInfoMargin; + return this; + } + + public double getFeederInfosIntraMargin() { + return feederInfosIntraMargin; + } + + public SvgParameters setFeederInfosIntraMargin(double feederInfosIntraMargin) { + this.feederInfosIntraMargin = feederInfosIntraMargin; + return this; + } + + public double getFeederInfosOuterMargin() { + return feederInfosOuterMargin; + } + + public SvgParameters setFeederInfosOuterMargin(double feederInfosOuterMargin) { + this.feederInfosOuterMargin = feederInfosOuterMargin; + return this; + } + + public boolean isFeederInfoSymmetry() { + return feederInfoSymmetry; + } + + public SvgParameters setFeederInfoSymmetry(boolean feederInfoSymmetry) { + this.feederInfoSymmetry = feederInfoSymmetry; + return this; + } + + public boolean isAddNodesInfos() { + return addNodesInfos; + } + + public SvgParameters setAddNodesInfos(boolean addNodesInfos) { + this.addNodesInfos = addNodesInfos; + return this; + } + + public boolean isUseName() { + return useName; + } + + public SvgParameters setUseName(boolean useName) { + this.useName = useName; + return this; + } + + public double getAngleLabelShift() { + return angleLabelShift; + } + + public SvgParameters setAngleLabelShift(double angleLabelShift) { + this.angleLabelShift = angleLabelShift; + return this; + } + + public boolean isLabelCentered() { + return labelCentered; + } + + public SvgParameters setLabelCentered(boolean labelCentered) { + this.labelCentered = labelCentered; + return this; + } + + public boolean isLabelDiagonal() { + return labelDiagonal; + } + + public SvgParameters setLabelDiagonal(boolean labelDiagonal) { + this.labelDiagonal = labelDiagonal; + return this; + } + + public boolean isTooltipEnabled() { + return tooltipEnabled; + } + + public SvgParameters setTooltipEnabled(boolean tooltipEnabled) { + this.tooltipEnabled = tooltipEnabled; + return this; + } + + public boolean isSvgWidthAndHeightAdded() { + return svgWidthAndHeightAdded; + } + + public SvgParameters setSvgWidthAndHeightAdded(boolean svgWidthAndHeightAdded) { + this.svgWidthAndHeightAdded = svgWidthAndHeightAdded; + return this; + } + + public CssLocation getCssLocation() { + return cssLocation; + } + + public SvgParameters setCssLocation(CssLocation cssLocation) { + Objects.requireNonNull(cssLocation); + this.cssLocation = cssLocation; + return this; + } + + public boolean isAvoidSVGComponentsDuplication() { + return avoidSVGComponentsDuplication; + } + + public SvgParameters setAvoidSVGComponentsDuplication(boolean avoidSVGComponentsDuplication) { + this.avoidSVGComponentsDuplication = avoidSVGComponentsDuplication; + return this; + } + + public String getDiagramName() { + return diagramName; + } + + public SvgParameters setDiagramName(String diagramName) { + this.diagramName = diagramName; + return this; + } + + public boolean isDrawStraightWires() { + return drawStraightWires; + } + + public SvgParameters setDrawStraightWires(boolean drawStraightWires) { + this.drawStraightWires = drawStraightWires; + return this; + } + + public boolean isShowGrid() { + return showGrid; + } + + public SvgParameters setShowGrid(boolean showGrid) { + this.showGrid = showGrid; + return this; + } + + public boolean isShowInternalNodes() { + return showInternalNodes; + } + + public SvgParameters setShowInternalNodes(boolean showInternalNodes) { + this.showInternalNodes = showInternalNodes; + return this; + } + + public boolean isDisplayCurrentFeederInfo() { + return this.displayCurrentFeederInfo; + } + + public SvgParameters setDisplayCurrentFeederInfo(boolean displayCurrentFeederInfo) { + this.displayCurrentFeederInfo = displayCurrentFeederInfo; + return this; + } +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/AbstractStyleProvider.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/AbstractStyleProvider.java index 175e0e34b..a834b3738 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/AbstractStyleProvider.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/AbstractStyleProvider.java @@ -19,7 +19,7 @@ import com.powsybl.sld.model.nodes.FeederNode; import com.powsybl.sld.model.nodes.Node; import com.powsybl.sld.model.nodes.SwitchNode; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.LabelProvider; import com.powsybl.sld.svg.DirectionalFeederInfo; import com.powsybl.sld.svg.FeederInfo; @@ -62,7 +62,7 @@ private static boolean isEquivalentToInternalNode(Node node) { } @Override - public List getNodeDecoratorStyles(DiagramLabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary) { + public List getNodeDecoratorStyles(LabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary) { return componentLibrary.getComponentStyleClass(nodeDecorator.getType()) .map(List::of) .orElse(Collections.emptyList()); @@ -94,7 +94,7 @@ public List getFeederInfoStyles(FeederInfo info) { List styles = new ArrayList<>(); styles.add(StyleClassConstants.FEEDER_INFO); if (info instanceof DirectionalFeederInfo) { - styles.add(((DirectionalFeederInfo) info).getDirection() == DiagramLabelProvider.LabelDirection.OUT ? StyleClassConstants.OUT_CLASS : StyleClassConstants.IN_CLASS); + styles.add(((DirectionalFeederInfo) info).getDirection() == LabelProvider.LabelDirection.OUT ? StyleClassConstants.OUT_CLASS : StyleClassConstants.IN_CLASS); } return styles; } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/DefaultStyleProviderFactory.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/DefaultStyleProviderFactory.java new file mode 100644 index 000000000..6240818b6 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/DefaultStyleProviderFactory.java @@ -0,0 +1,25 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.sld.svg.styles; + +import com.powsybl.iidm.network.Network; +import com.powsybl.sld.svg.styles.iidm.HighlightLineStateStyleProvider; +import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider; + +/** + * + * @author Sophie Frasnedo + */ + +public class DefaultStyleProviderFactory implements StyleProviderFactory { + @Override + public StyleProvider create(Network network) { + return new StyleProvidersList(new TopologicalStyleProvider(network), new HighlightLineStateStyleProvider(network)); + } +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/EmptyStyleProvider.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/EmptyStyleProvider.java index e704e5dc1..9f321e8cd 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/EmptyStyleProvider.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/EmptyStyleProvider.java @@ -15,7 +15,7 @@ import com.powsybl.sld.model.nodes.Edge; import com.powsybl.sld.model.nodes.Node; import com.powsybl.sld.svg.BusInfo; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.LabelProvider; import com.powsybl.sld.svg.FeederInfo; import java.util.Collections; @@ -37,7 +37,7 @@ public List getNodeStyles(VoltageLevelGraph graph, Node node, ComponentL } @Override - public List getNodeDecoratorStyles(DiagramLabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary) { + public List getNodeDecoratorStyles(LabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary) { return Collections.emptyList(); } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/NominalVoltageStyleProviderFactory.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/NominalVoltageStyleProviderFactory.java new file mode 100644 index 000000000..480b1096a --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/NominalVoltageStyleProviderFactory.java @@ -0,0 +1,23 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.sld.svg.styles; + +import com.powsybl.iidm.network.Network; + +/** + * + * @author Sophie Frasnedo + */ + +public class NominalVoltageStyleProviderFactory implements StyleProviderFactory { + @Override + public StyleProvider create(Network network) { + return new NominalVoltageStyleProvider(); + } +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvider.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvider.java index a08e58235..b675d0fec 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvider.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvider.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg.styles; @@ -14,8 +15,8 @@ import com.powsybl.sld.model.nodes.Edge; import com.powsybl.sld.model.nodes.Node; import com.powsybl.sld.svg.BusInfo; -import com.powsybl.sld.svg.DiagramLabelProvider; import com.powsybl.sld.svg.FeederInfo; +import com.powsybl.sld.svg.LabelProvider; import java.net.URL; import java.util.List; @@ -31,7 +32,7 @@ public interface StyleProvider { List getNodeStyles(VoltageLevelGraph graph, Node node, ComponentLibrary componentLibrary, boolean showInternalNodes); - List getNodeDecoratorStyles(DiagramLabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary); + List getNodeDecoratorStyles(LabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary); List getBranchEdgeStyles(BranchEdge edge, ComponentLibrary componentLibrary); diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProviderFactory.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProviderFactory.java new file mode 100644 index 000000000..64ba97bc9 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProviderFactory.java @@ -0,0 +1,21 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.sld.svg.styles; + +import com.powsybl.iidm.network.Network; + +/** + * + * @author Sophie Frasnedo + */ + +@FunctionalInterface +public interface StyleProviderFactory { + StyleProvider create(Network network); +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvidersList.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvidersList.java index 38d898934..b9c731e65 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvidersList.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/StyleProvidersList.java @@ -15,7 +15,7 @@ import com.powsybl.sld.model.nodes.Edge; import com.powsybl.sld.model.nodes.Node; import com.powsybl.sld.svg.BusInfo; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.LabelProvider; import com.powsybl.sld.svg.FeederInfo; import java.net.URL; @@ -49,7 +49,7 @@ public List getNodeStyles(VoltageLevelGraph graph, Node node, ComponentL } @Override - public List getNodeDecoratorStyles(DiagramLabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary) { + public List getNodeDecoratorStyles(LabelProvider.NodeDecorator nodeDecorator, Node node, ComponentLibrary componentLibrary) { return concatenateLists(sp -> sp.getNodeDecoratorStyles(nodeDecorator, node, componentLibrary)); } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java index 6df017a18..8f13e1175 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java @@ -3,17 +3,20 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld; import com.google.common.io.ByteStreams; import com.powsybl.sld.layout.*; +import com.powsybl.sld.library.ComponentLibrary; import com.powsybl.sld.library.ConvergenceComponentLibrary; import com.powsybl.sld.library.ResourcesComponentLibrary; 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.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.LabelProvider; +import com.powsybl.sld.svg.SvgParameters; import com.powsybl.sld.svg.styles.StyleProvider; import org.apache.commons.io.output.NullWriter; @@ -39,6 +42,16 @@ public abstract class AbstractTestCase { protected final LayoutParameters layoutParameters = createDefaultLayoutParameters(); + protected final SvgParameters svgParameters = new SvgParameters() + .setFeederInfosIntraMargin(10) + .setUseName(true) + .setSvgWidthAndHeightAdded(true) + .setCssLocation(SvgParameters.CssLocation.INSERTED_IN_SVG) + .setFeederInfosOuterMargin(20) + .setDrawStraightWires(false) + .setShowGrid(false) + .setShowInternalNodes(false); + private static LayoutParameters createDefaultLayoutParameters() { return new LayoutParameters() .setAdaptCellHeightToContent(true) @@ -48,17 +61,10 @@ private static LayoutParameters createDefaultLayoutParameters() { .setExternCellHeight(250) .setInternCellHeight(40) .setStackHeight(30) - .setShowGrid(false) - .setShowInternalNodes(false) - .setScaleFactor(1) - .setFeederInfosOuterMargin(20) - .setDrawStraightWires(false) + .setCgmesScaleFactor(1) .setHorizontalSnakeLinePadding(30) .setVerticalSnakeLinePadding(30) - .setCssLocation(LayoutParameters.CssLocation.INSERTED_IN_SVG) - .setSvgWidthAndHeightAdded(true) - .setUseName(true) - .setFeederInfosIntraMargin(10); + .setCgmesUseNames(true); } protected ResourcesComponentLibrary getResourcesComponentLibrary() { @@ -72,10 +78,6 @@ protected static String normalizeLineSeparator(String str) { public abstract void setUp() throws IOException; - String getName() { - return getClass().getSimpleName(); - } - protected void writeDebugFilesFromJson(String refMetdataName, StringWriter writer, StringWriter metadataWriter) { if (debugJsonFiles && metadataWriter != null) { writeToFileInDebugDir(refMetdataName, metadataWriter); @@ -115,10 +117,10 @@ protected void overrideTestReference(String filename, StringWriter content) { public abstract String toSVG(Graph g, String filename); - public String toSVG(Graph graph, String filename, DiagramLabelProvider labelProvider, StyleProvider styleProvider) { + public String toSVG(Graph graph, String filename, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters, LabelProvider labelProvider, StyleProvider styleProvider) { + try (StringWriter writer = new StringWriter()) { - SingleLineDiagram.draw(graph, writer, new NullWriter(), layoutParameters, componentLibrary, - labelProvider, styleProvider, ""); + SingleLineDiagram.draw(graph, writer, new NullWriter(), componentLibrary, layoutParameters, svgParameters, labelProvider, styleProvider); if (debugSvgFiles) { writeToFileInDebugDir(filename, writer); @@ -133,18 +135,15 @@ public String toSVG(Graph graph, String filename, DiagramLabelProvider labelProv } } - public boolean compareMetadata(VoltageLevelGraph graph, String refMetadataName, - VoltageLevelLayoutFactory voltageLevelLayoutFactory, - DiagramLabelProvider labelProvider, StyleProvider styleProvider) { + public boolean compareMetadata(VoltageLevelGraph graph, String refMetadataName, VoltageLevelLayoutFactory voltageLevelLayoutFactory, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters, LabelProvider labelProvider, StyleProvider styleProvider) { InputStream isRefMetadata = Objects.requireNonNull(getClass().getResourceAsStream(refMetadataName)); try (StringWriter writer = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { - voltageLevelLayoutFactory.create(graph).run(layoutParameters); - SingleLineDiagram.draw(graph, writer, metadataWriter, layoutParameters, componentLibrary, - labelProvider, styleProvider, ""); + voltageLevelLayoutFactory.create(graph).run(this.layoutParameters); + SingleLineDiagram.draw(graph, writer, metadataWriter, componentLibrary, layoutParameters, svgParameters, labelProvider, styleProvider); if (debugJsonFiles) { writeToFileInDebugDir(refMetadataName, metadataWriter); @@ -164,18 +163,15 @@ public boolean compareMetadata(VoltageLevelGraph graph, String refMetadataName, } } - public boolean compareMetadata(SubstationGraph graph, String refMetdataName, - SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vlLayoutFactory, - DiagramLabelProvider labelProvider, StyleProvider styleProvider) { + public boolean compareMetadata(SubstationGraph graph, String refMetdataName, SubstationLayoutFactory substationLayoutFactory, VoltageLevelLayoutFactory voltageLevelLayoutFactory, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters, LabelProvider labelProvider, StyleProvider styleProvider) { InputStream isRefMetadata = Objects.requireNonNull(getClass().getResourceAsStream(refMetdataName)); try (StringWriter writer = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { - sLayoutFactory.create(graph, vlLayoutFactory).run(layoutParameters); - SingleLineDiagram.draw(graph, writer, metadataWriter, layoutParameters, componentLibrary, - labelProvider, styleProvider, ""); + substationLayoutFactory.create(graph, voltageLevelLayoutFactory).run(this.layoutParameters); + SingleLineDiagram.draw(graph, writer, metadataWriter, componentLibrary, layoutParameters, svgParameters, labelProvider, styleProvider); if (debugJsonFiles) { writeToFileInDebugDir(refMetdataName, metadataWriter); @@ -240,4 +236,5 @@ protected void voltageLevelGraphLayout(VoltageLevelGraph voltageLevelGraph) { protected void substationGraphLayout(SubstationGraph substationGraph) { new HorizontalSubstationLayoutFactory().create(substationGraph, new PositionVoltageLevelLayoutFactory()).run(layoutParameters); } + } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/AbstractTestCaseIidm.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/AbstractTestCaseIidm.java index 184fa2dab..cdbb9e969 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/AbstractTestCaseIidm.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/AbstractTestCaseIidm.java @@ -3,10 +3,13 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; -import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.Substation; +import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.sld.AbstractTestCase; import com.powsybl.sld.builders.GraphBuilder; import com.powsybl.sld.layout.HorizontalSubstationLayoutFactory; @@ -14,8 +17,8 @@ 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.svg.DefaultDiagramLabelProvider; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.DefaultLabelProvider; +import com.powsybl.sld.svg.LabelProvider; import com.powsybl.sld.svg.styles.StyleProvider; import com.powsybl.sld.svg.styles.StyleProvidersList; import com.powsybl.sld.svg.styles.iidm.HighlightLineStateStyleProvider; @@ -36,11 +39,11 @@ public abstract class AbstractTestCaseIidm extends AbstractTestCase { @Override public String toSVG(Graph g, String filename) { - return toSVG(g, filename, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider()); + return toSVG(g, filename, componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider()); } - protected DiagramLabelProvider getDefaultDiagramLabelProvider() { - return new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters); + protected LabelProvider getDefaultDiagramLabelProvider() { + return new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters); } protected StyleProvider getDefaultDiagramStyleProvider() { diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestBattery.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestBattery.java index 2c31e37d0..0b20531df 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestBattery.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestBattery.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -36,6 +37,6 @@ void test() { voltageLevelGraphLayout(g); // write SVG and compare to reference - assertEquals(toString("/TestBatteries.svg"), toSVG(g, "/TestBatteries.svg")); + assertEquals(toString("/TestBatteries.svg"), toSVG(g, "/TestBatteries.svg", getResourcesComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11FlatDesignComponents.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11FlatDesignComponents.java index 67822c99d..8755978f3 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11FlatDesignComponents.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11FlatDesignComponents.java @@ -8,7 +8,7 @@ package com.powsybl.sld.iidm; import com.powsybl.diagram.test.Networks; -import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.sld.builders.NetworkGraphBuilder; import com.powsybl.sld.library.FlatDesignLibrary; import com.powsybl.sld.library.ResourcesComponentLibrary; @@ -69,6 +69,7 @@ void test() { substationGraphLayout(g); String filename = "/TestCase11FlatDesign.svg"; - assertEquals(toString(filename), toSVG(g, filename)); + + assertEquals(toString(filename), toSVG(g, filename, getResourcesComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11SubstationGraph.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11SubstationGraph.java index d37be62d2..1b62bd4bd 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11SubstationGraph.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase11SubstationGraph.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -14,8 +15,8 @@ import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactory; import com.powsybl.sld.layout.VerticalSubstationLayoutFactory; import com.powsybl.sld.model.graphs.SubstationGraph; +import com.powsybl.sld.svg.DefaultLabelProvider; import com.powsybl.sld.svg.styles.BasicStyleProvider; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; import com.powsybl.sld.svg.styles.NominalVoltageStyleProvider; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; @@ -78,7 +79,7 @@ private void runHorizontalALignmentTest(LayoutParameters.Alignment alignment) { substationGraphLayout(g); String filename = "/TestCase11SubstationGraphH" + StringUtils.capitalize(alignment.name().toLowerCase()) + ".svg"; - assertEquals(toString(filename), toSVG(g, filename)); + assertEquals(toString(filename), toSVG(g, filename, componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } @Test @@ -157,8 +158,10 @@ void testMetadataWithHvdcLines() { assertTrue(compareMetadata(g, "/substDiag_with_hvdc_line_metadata.json", new HorizontalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory(), - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - new BasicStyleProvider())); + componentLibrary, + layoutParameters, + svgParameters, + new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters), new BasicStyleProvider())); } @Test @@ -167,11 +170,8 @@ void testHorizontalDefaultStyle() { // (with horizontal substation layout) SubstationGraph substationGraph = graphBuilder.buildSubstationGraph(substation.getId()); - assertTrue(compareMetadata(substationGraph, "/substDiag_metadata.json", - new HorizontalSubstationLayoutFactory(), - new PositionVoltageLevelLayoutFactory(), - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - new BasicStyleProvider())); + assertTrue(compareMetadata(substationGraph, "/substDiag_metadata.json", new HorizontalSubstationLayoutFactory(), + new PositionVoltageLevelLayoutFactory(), componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new BasicStyleProvider())); } @Test @@ -180,10 +180,6 @@ void testHorizontalNominalStyle() { // (with horizontal substation layout) SubstationGraph graph = graphBuilder.buildSubstationGraph(substation.getId()); - assertTrue(compareMetadata(graph, "/substDiag_metadata.json", - new HorizontalSubstationLayoutFactory(), - new PositionVoltageLevelLayoutFactory(), - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - new NominalVoltageStyleProvider())); + assertTrue(compareMetadata(graph, "/substDiag_metadata.json", new HorizontalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory(), componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new NominalVoltageStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase12GraphWith3WT.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase12GraphWith3WT.java index 0731f9a02..86ca7c023 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase12GraphWith3WT.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase12GraphWith3WT.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -11,12 +12,9 @@ import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.sld.builders.NetworkGraphBuilder; import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactory; -import com.powsybl.sld.library.ComponentLibrary; import com.powsybl.sld.library.ConvergenceComponentLibrary; import com.powsybl.sld.model.graphs.VoltageLevelGraph; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; import com.powsybl.sld.svg.styles.NominalVoltageStyleProvider; -import com.powsybl.sld.svg.styles.StyleProvider; import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -259,55 +257,42 @@ void testVl3() { void testMetadata() { // Optimize SVG by avoiding duplication - layoutParameters.setAvoidSVGComponentsDuplication(true) + svgParameters.setAvoidSVGComponentsDuplication(true) .setAddNodesInfos(true); // compare metadata of voltage level diagram with reference VoltageLevelGraph graph = graphBuilder.buildVoltageLevelGraph(vl1.getId()); - assertTrue(compareMetadata(graph, "/vlDiag_metadata.json", - new PositionVoltageLevelLayoutFactory(), - new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), - new NominalVoltageStyleProvider())); + assertTrue(compareMetadata(graph, "/vlDiag_metadata.json", new PositionVoltageLevelLayoutFactory(), componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new NominalVoltageStyleProvider())); } @Test void testNodesInfosNominalVoltageStyle() { separateBusVoltages(); - layoutParameters.setAddNodesInfos(true); + svgParameters.setAddNodesInfos(true); // build voltage level 1 graph VoltageLevelGraph g1 = graphBuilder.buildVoltageLevelGraph(vl1.getId()); voltageLevelGraphLayout(g1); - StyleProvider vNomStyleProvider = new NominalVoltageStyleProvider(); - - ComponentLibrary componentLibrary = new ConvergenceComponentLibrary(); - DefaultDiagramLabelProvider initProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters); - // write SVGs and compare to reference assertEquals(toString("/TestCase12GraphWithNodesInfosNominalVoltage.svg"), - toSVG(g1, "/TestCase12GraphWithNodesInfosNominalVoltage.svg", initProvider, vNomStyleProvider)); + toSVG(g1, "/TestCase12GraphWithNodesInfosNominalVoltage.svg", new ConvergenceComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new NominalVoltageStyleProvider())); } @Test void testNodesInfosTopologicalStyle() { separateBusVoltages(); - layoutParameters.setAddNodesInfos(true); + //parametrize diagram + svgParameters.setAddNodesInfos(true); VoltageLevelGraph g1 = graphBuilder.buildVoltageLevelGraph(vl1.getId()); - voltageLevelGraphLayout(g1); - StyleProvider topoStyleProvider = new TopologicalStyleProvider(network); - - ComponentLibrary componentLibrary = new ConvergenceComponentLibrary(); - DefaultDiagramLabelProvider initProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters); - assertEquals(toString("/TestCase12GraphWithNodesInfosTopological.svg"), - toSVG(g1, "/TestCase12GraphWithNodesInfosTopological.svg", initProvider, topoStyleProvider)); + toSVG(g1, "/TestCase12GraphWithNodesInfosTopological.svg", new ConvergenceComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new TopologicalStyleProvider(network))); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase13ZoneGraph.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase13ZoneGraph.java index c915a0e73..a198d8790 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase13ZoneGraph.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase13ZoneGraph.java @@ -3,14 +3,15 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; import com.powsybl.diagram.test.Networks; -import com.powsybl.iidm.network.*; import com.powsybl.sld.builders.NetworkGraphBuilder; import com.powsybl.sld.layout.*; import com.powsybl.sld.model.graphs.ZoneGraph; +import com.powsybl.sld.svg.SvgParameters; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +30,7 @@ class TestCase13ZoneGraph extends AbstractTestCaseIidm { @BeforeEach public void setUp() { - layoutParameters.setCssLocation(LayoutParameters.CssLocation.INSERTED_IN_SVG); + svgParameters.setCssLocation(SvgParameters.CssLocation.INSERTED_IN_SVG); network = Networks.createNetworkWithLine(); // In order to keep same results -> can be removed later network.getVoltageLevelStream().forEach(vl -> vl.setNominalV(380)); diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase15GraphWithVoltageIndicator.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase15GraphWithVoltageIndicator.java index d5f35dcf1..984c7dbbe 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase15GraphWithVoltageIndicator.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase15GraphWithVoltageIndicator.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -14,8 +15,9 @@ import com.powsybl.sld.model.graphs.VoltageLevelGraph; import com.powsybl.sld.model.nodes.BusNode; import com.powsybl.sld.svg.BusInfo; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.DefaultLabelProvider; +import com.powsybl.sld.svg.DefaultSVGWriter; +import com.powsybl.sld.svg.LabelProvider; import com.powsybl.sld.svg.styles.BasicStyleProvider; import com.powsybl.sld.svg.styles.StyleProvider; import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider; @@ -53,16 +55,18 @@ public boolean isPowered() { } } - private DiagramLabelProvider withFullBusInfoProvider; + private LabelProvider withFullBusInfoProvider; - private DiagramLabelProvider withIncompleteBusInfoProvider; + private LabelProvider withIncompleteBusInfoProvider; @BeforeEach public void setUp() throws IOException { network = Networks.createNetworkWithFiveBusesFourLoads(); graphBuilder = new NetworkGraphBuilder(network); + svgParameters.setBusInfoMargin(5); + + withFullBusInfoProvider = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters) { - withFullBusInfoProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) { @Override public Optional getBusInfo(BusNode node) { Objects.requireNonNull(node); @@ -84,7 +88,8 @@ public Optional getBusInfo(BusNode node) { } }; - withIncompleteBusInfoProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) { + withIncompleteBusInfoProvider = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters) { + @Override public Optional getBusInfo(BusNode node) { Objects.requireNonNull(node); @@ -112,7 +117,7 @@ protected ResourcesComponentLibrary getResourcesComponentLibrary() { @Test void testWithoutBusInfo() { - runTest(new BasicStyleProvider(), "/TestCase15GraphWithoutVoltageIndicator.svg", new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters)); + runTest(new BasicStyleProvider(), "/TestCase15GraphWithoutVoltageIndicator.svg", new DefaultLabelProvider(network, getResourcesComponentLibrary(), layoutParameters, svgParameters)); } @Test @@ -137,8 +142,7 @@ public List getBusInfoStyle(BusInfo info) { runTest(styleProvider, "/TestCase15GraphWithVoltageIndicatorTopological.svg", withFullBusInfoProvider); } - private void runTest(StyleProvider styleProvider, String filename, DiagramLabelProvider labelProvider) { - layoutParameters.setBusInfoMargin(5); + private void runTest(StyleProvider styleProvider, String filename, LabelProvider labelProvider) { // build graph VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph("vl1"); @@ -152,6 +156,7 @@ private void runTest(StyleProvider styleProvider, String filename, DiagramLabelP .run(layoutParameters); // write SVG and compare to reference - assertEquals(toString(filename), toSVG(g, filename, labelProvider, styleProvider)); + DefaultSVGWriter defaultSVGWriter = new DefaultSVGWriter(getResourcesComponentLibrary(), layoutParameters, svgParameters); + assertEquals(toString(filename), toSVG(g, filename, getResourcesComponentLibrary(), layoutParameters, svgParameters, labelProvider, styleProvider)); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseConsecutiveShunts.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseConsecutiveShunts.java index 2f954a5f5..7e108bd76 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseConsecutiveShunts.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseConsecutiveShunts.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -11,9 +12,9 @@ import com.powsybl.sld.model.coordinate.Direction; import com.powsybl.sld.model.graphs.VoltageLevelGraph; import com.powsybl.sld.model.nodes.Node; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.DefaultLabelProvider; import com.powsybl.sld.svg.LabelPosition; +import com.powsybl.sld.svg.LabelProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -28,17 +29,17 @@ */ class TestCaseConsecutiveShunts extends AbstractTestCaseIidm { + LabelProvider labelProvider; + @BeforeEach public void setUp() { - layoutParameters.setShowInternalNodes(true); + svgParameters.setShowInternalNodes(true); network = Network.read("consecutive_shunts.xiidm", getClass().getResourceAsStream("/consecutive_shunts.xiidm")); vl = network.getVoltageLevel("AU"); graphBuilder = new NetworkGraphBuilder(network); - } - @Override - protected DiagramLabelProvider getDefaultDiagramLabelProvider() { - return new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) { + labelProvider = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters) { + @Override public List getNodeLabels(Node node, Direction direction) { return node.isFictitious() @@ -46,6 +47,7 @@ public List getNodeLabels(Node node, Direction direction) { : Collections.singletonList(new NodeLabel(node.getId(), new LabelPosition("NW", 4, -1, true, 0))); } }; + } @Test @@ -57,7 +59,7 @@ void test() throws IOException { voltageLevelGraphLayout(g); // write SVG and compare to reference - assertEquals(toString("/consecutive_shunts.svg"), toSVG(g, "/consecutive_shunts.svg")); + assertEquals(toString("/consecutive_shunts.svg"), toSVG(g, "/consecutive_shunts.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousBus.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousBus.java index 2948dbf76..c97714dd7 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousBus.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousBus.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -101,7 +102,7 @@ void testBasic() { // write Json and compare to reference assertEquals(toString("/TestCaseFictitiousBus.svg"), - toSVG(g, "/TestCaseFictitiousBus.svg", getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); + toSVG(g, "/TestCaseFictitiousBus.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } @Test @@ -114,6 +115,6 @@ void testTopological() { // write Json and compare to reference assertEquals(toString("/TestCaseFictitiousBusTopological.svg"), - toSVG(g, "/TestCaseFictitiousBusTopological.svg", getDefaultDiagramLabelProvider(), new TopologicalStyleProvider(network))); + toSVG(g, "/TestCaseFictitiousBusTopological.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new TopologicalStyleProvider(network))); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousSwitchNode.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousSwitchNode.java index 5c644c999..2b30a7962 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousSwitchNode.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseFictitiousSwitchNode.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -47,7 +48,7 @@ void keepFictitiousSwitchNodesTest() { factory.create(g1).run(layoutParameters); // write svg and compare to reference - assertEquals(toString("/TestCaseKeepFictitiousSwitchNode.svg"), toSVG(g1, "/TestCaseKeepFictitiousSwitchNode.svg")); + assertEquals(toString("/TestCaseKeepFictitiousSwitchNode.svg"), toSVG(g1, "/TestCaseKeepFictitiousSwitchNode.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } @Test @@ -62,7 +63,7 @@ void removeFictitiousSwitchNodesTest() { factory.create(g2).run(layoutParameters); // write svg and compare to reference - assertEquals(toString("/TestCaseRemoveFictitiousSwitchNode.svg"), toSVG(g2, "/TestCaseRemoveFictitiousSwitchNode.svg")); + assertEquals(toString("/TestCaseRemoveFictitiousSwitchNode.svg"), toSVG(g2, "/TestCaseRemoveFictitiousSwitchNode.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseLoadBreakSwitch.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseLoadBreakSwitch.java index 7b5c98f6f..cc346c279 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseLoadBreakSwitch.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCaseLoadBreakSwitch.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -47,6 +48,7 @@ public void setUp() { Networks.createSwitch(vl, "b3", "b3", SwitchKind.LOAD_BREAK_SWITCH, false, true, false, 1, 5); Networks.createSwitch(vl, "b4", "b4", SwitchKind.LOAD_BREAK_SWITCH, false, true, false, 5, 6); Networks.createSwitch(vl, "b5", "b5", SwitchKind.LOAD_BREAK_SWITCH, false, true, false, 5, 3); + } @Test @@ -58,6 +60,6 @@ void test() { voltageLevelGraphLayout(g); // write Json and compare to reference - assertEquals(toString("/TestCaseLoadBreakSwitch.svg"), toSVG(g, "/TestCaseLoadBreakSwitch.svg", getDefaultDiagramLabelProvider(), new TopologicalStyleProvider(network))); + assertEquals(toString("/TestCaseLoadBreakSwitch.svg"), toSVG(g, "/TestCaseLoadBreakSwitch.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new TopologicalStyleProvider(network))); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestComplexParallelLegsInternalPst.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestComplexParallelLegsInternalPst.java index 765a476ed..3757035b9 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestComplexParallelLegsInternalPst.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestComplexParallelLegsInternalPst.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -44,6 +45,7 @@ void test() { // write SVG and compare to reference String filename = "/TestComplexParallelLegsInternalPst.svg"; - assertEquals(toString(filename), toSVG(g, filename)); + + assertEquals(toString(filename), toSVG(g, filename, getResourcesComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestDisconnectedComponentsBusBreaker.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestDisconnectedComponentsBusBreaker.java index 961328091..bfd19b1fd 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestDisconnectedComponentsBusBreaker.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestDisconnectedComponentsBusBreaker.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -45,6 +46,6 @@ void testDisconnectedComponents() { // write SVG and compare to reference assertEquals(toString("/disconnectedComponentsBusBreaker.svg"), - toSVG(g, "/disconnectedComponentsBusBreaker.svg", getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); + toSVG(g, "/disconnectedComponentsBusBreaker.svg")); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestFeederInfos.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestFeederInfos.java index 73125b53a..4b373ae22 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestFeederInfos.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestFeederInfos.java @@ -3,12 +3,12 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; import com.powsybl.diagram.test.Networks; import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory; - import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.sld.builders.NetworkGraphBuilder; @@ -16,10 +16,10 @@ import com.powsybl.sld.model.graphs.VoltageLevelGraph; import com.powsybl.sld.model.nodes.FeederNode; import com.powsybl.sld.model.nodes.Node; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.DefaultLabelProvider; import com.powsybl.sld.svg.DirectionalFeederInfo; import com.powsybl.sld.svg.FeederInfo; +import com.powsybl.sld.svg.LabelProvider; import com.powsybl.sld.svg.styles.AnimatedFeederInfoStyleProvider; import com.powsybl.sld.svg.styles.BasicStyleProvider; import com.powsybl.sld.svg.styles.StyleProvider; @@ -31,9 +31,6 @@ import java.util.*; import static com.powsybl.sld.library.ComponentTypeName.*; - -import static com.powsybl.sld.library.ComponentTypeName.ARROW_ACTIVE; -import static com.powsybl.sld.library.ComponentTypeName.ARROW_REACTIVE; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -68,15 +65,17 @@ void testManyFeederInfos() { // build graph VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId()); - layoutParameters.setSpaceForFeederInfos(100) + layoutParameters.setSpaceForFeederInfos(100); + + svgParameters.setPowerValuePrecision(3) .setFeederInfosIntraMargin(5) - .setPowerValuePrecision(3); + .setDisplayCurrentFeederInfo(true); // Run layout voltageLevelGraphLayout(g); - // many feeder values provider example for the test : - DiagramLabelProvider manyFeederInfoProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) { + // many feeder values provider example for the test: + LabelProvider labelManyFeederInfoProvider = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters) { @Override public List getFeederInfos(FeederNode node) { @@ -86,7 +85,7 @@ public List getFeederInfos(FeederNode node) { new DirectionalFeederInfo(ARROW_REACTIVE, LabelDirection.IN, null, "3000", null), new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "40", null), // Not displayed new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "50", null)); - boolean feederArrowSymmetry = node.getDirection() == Direction.TOP || layoutParameters.isFeederInfoSymmetry(); + boolean feederArrowSymmetry = node.getDirection() == Direction.TOP || svgParameters.isFeederInfoSymmetry(); if (!feederArrowSymmetry) { Collections.reverse(feederInfos); } @@ -94,30 +93,31 @@ public List getFeederInfos(FeederNode node) { } @Override - public List getNodeDecorators(Node node, Direction direction) { + public List getNodeDecorators(Node node, Direction direction) { return new ArrayList<>(); } + }; - // write SVG and compare to reference - assertEquals(toString("/TestFeederInfos.svg"), toSVG(g, "/TestFeederInfos.svg", manyFeederInfoProvider, new BasicStyleProvider())); + +// write SVG and compare to reference + assertEquals(toString("/TestFeederInfos.svg"), toSVG(g, "/TestFeederInfos.svg", componentLibrary, layoutParameters, svgParameters, labelManyFeederInfoProvider, new BasicStyleProvider())); } @Test void testAllPossibleInfoItems() { + layoutParameters.setSpaceForFeederInfos(100); + svgParameters.setFeederInfosIntraMargin(5) + .setPowerValuePrecision(0) + .setDisplayCurrentFeederInfo(true); // build graph network.getLoad("l").getTerminal().setP(100).setQ(10).getBusView().getBus().setV(vl.getNominalV()); VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId()); - layoutParameters.setSpaceForFeederInfos(100) - .setFeederInfosIntraMargin(5) - .setPowerValuePrecision(0) - .setDisplayCurrentFeederInfo(true); - // Run layout voltageLevelGraphLayout(g); // write SVG and compare to reference - assertEquals(toString("/TestAllPossibleInfoItems.svg"), toSVG(g, "/TestAllPossibleInfoItems.svg", new DefaultDiagramLabelProvider(network, getResourcesComponentLibrary(), layoutParameters), new BasicStyleProvider())); + assertEquals(toString("/TestAllPossibleInfoItems.svg"), toSVG(g, "/TestAllPossibleInfoItems.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), new BasicStyleProvider())); } @Test @@ -127,7 +127,7 @@ void testFrenchFormatting() { network.getLoad("l").getTerminal().setP(1200.29); network.getLoad("l").getTerminal().setQ(-1); - layoutParameters.setLanguageTag("fr").setPowerValuePrecision(1); + svgParameters.setLanguageTag("fr").setPowerValuePrecision(1); // build graph VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId()); @@ -136,15 +136,15 @@ void testFrenchFormatting() { voltageLevelGraphLayout(g); // write SVG and compare to reference - assertEquals(toString("/TestFormattingFeederInfos.svg"), toSVG(g, "/TestFormattingFeederInfos.svg")); + assertEquals(toString("/TestFormattingFeederInfos.svg"), toSVG(g, "/TestFormattingFeederInfos.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } @Test void testBuildFeederInfosWithCurrent() { Network network = IeeeCdfNetworkFactory.create9(); - layoutParameters.setDisplayCurrentFeederInfo(true); + svgParameters.setDisplayCurrentFeederInfo(true); VoltageLevelGraph g = new NetworkGraphBuilder(network).buildVoltageLevelGraph("VL5"); - List feederInfoList = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters).getFeederInfos(g.getFeederNodes().get(0)); + List feederInfoList = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters).getFeederInfos(g.getFeederNodes().get(0)); assertEquals(3, feederInfoList.size()); assertEquals(ARROW_ACTIVE, feederInfoList.get(0).getComponentType()); assertEquals(ARROW_REACTIVE, feederInfoList.get(1).getComponentType()); @@ -154,9 +154,9 @@ void testBuildFeederInfosWithCurrent() { @Test void testBuildFeederInfosWithoutCurrent() { Network network = IeeeCdfNetworkFactory.create9(); - layoutParameters.setDisplayCurrentFeederInfo(false); + svgParameters.setDisplayCurrentFeederInfo(false); VoltageLevelGraph g = new NetworkGraphBuilder(network).buildVoltageLevelGraph("VL5"); - List feederInfoList = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters).getFeederInfos(g.getFeederNodes().get(0)); + List feederInfoList = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters).getFeederInfos(g.getFeederNodes().get(0)); assertEquals(2, feederInfoList.size()); assertEquals(ARROW_ACTIVE, feederInfoList.get(0).getComponentType()); assertEquals(ARROW_REACTIVE, feederInfoList.get(1).getComponentType()); @@ -176,9 +176,10 @@ void testAnimation() { network.getLoad("l2").getTerminal().setP(501.0); network.getLoad("l2").getTerminal().setQ(0.0); - layoutParameters.setFeederInfosIntraMargin(20); + svgParameters.setFeederInfosIntraMargin(20); + + LabelProvider labelProvider = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters) { - DiagramLabelProvider labelProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) { @Override public List getFeederInfos(FeederNode node) { Load l = network.getLoad("l"); @@ -216,6 +217,7 @@ public Optional getRightLabel() { }); } } + }; StyleProvider styleProvider = new StyleProvidersList( @@ -229,7 +231,6 @@ public Optional getRightLabel() { voltageLevelGraphLayout(g); // write SVG and compare to reference - assertEquals(toString("/TestAnimatedFeederInfos.svg"), toSVG(g, "/TestAnimatedFeederInfos.svg", labelProvider, styleProvider)); - + assertEquals(toString("/TestAnimatedFeederInfos.svg"), toSVG(g, "/TestAnimatedFeederInfos.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, styleProvider)); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesBusBreaker.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesBusBreaker.java index 3c7621052..e6cf4d1db 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesBusBreaker.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesBusBreaker.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -15,6 +16,7 @@ import com.powsybl.sld.layout.VerticalSubstationLayoutFactory; import com.powsybl.sld.model.graphs.SubstationGraph; import com.powsybl.sld.model.graphs.VoltageLevelGraph; +import com.powsybl.sld.svg.DefaultSVGWriter; import com.powsybl.sld.svg.styles.NominalVoltageStyleProvider; import com.powsybl.sld.svg.styles.StyleProvider; import org.junit.jupiter.api.BeforeEach; @@ -31,7 +33,7 @@ class TestInternalBranchesBusBreaker extends AbstractTestCaseIidm { @Override public StyleProvider getDefaultDiagramStyleProvider() { - // bypassing the config-test platform config to test the embedded base-voltages.yml file + // bypassing the sldParameters-test platform sldParameters to test the embedded base-voltages.yml file BaseVoltagesConfig baseVoltagesConfig = BaseVoltagesConfig.fromPlatformConfig(new PlatformConfig((ModuleConfigRepository) null, Path.of("./"))); return new NominalVoltageStyleProvider(baseVoltagesConfig); } @@ -52,8 +54,9 @@ void testVLGraph() { voltageLevelGraphLayout(g); // write SVG and compare to reference + DefaultSVGWriter defaultSVGWriter = new DefaultSVGWriter(componentLibrary, layoutParameters, svgParameters); assertEquals(toString("/InternalBranchesBusBreaker.svg"), - toSVG(g, "/InternalBranchesBusBreaker.svg", getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); + toSVG(g, "/InternalBranchesBusBreaker.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } @Test diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesNodeBreaker.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesNodeBreaker.java index 8e790e80e..3e756e590 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesNodeBreaker.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestInternalBranchesNodeBreaker.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -12,6 +13,7 @@ import com.powsybl.sld.layout.VerticalSubstationLayoutFactory; import com.powsybl.sld.model.graphs.SubstationGraph; import com.powsybl.sld.model.graphs.VoltageLevelGraph; +import com.powsybl.sld.svg.DefaultSVGWriter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,8 +40,9 @@ void testVLGraph() { voltageLevelGraphLayout(g); // write SVG and compare to reference + DefaultSVGWriter defaultSVGWriter = new DefaultSVGWriter(componentLibrary, layoutParameters, svgParameters); assertEquals(toString("/InternalBranchesNodeBreaker.svg"), - toSVG(g, "/InternalBranchesNodeBreaker.svg", getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); + toSVG(g, "/InternalBranchesNodeBreaker.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsBusBreaker.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsBusBreaker.java index 09d4a224a..a57d960c9 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsBusBreaker.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsBusBreaker.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -36,6 +37,6 @@ void testBranchStatusDecorators() { // write SVG and compare to reference assertEquals(toString("/NodeDecoratorsBranchStatusBusBreaker.svg"), - toSVG(g, "/NodeDecoratorsBranchStatusBusBreaker.svg", getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); + toSVG(g, "/NodeDecoratorsBranchStatusBusBreaker.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsNodeBreaker.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsNodeBreaker.java index ab2de3c36..2a8347ece 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsNodeBreaker.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestNodeDecoratorsNodeBreaker.java @@ -3,20 +3,21 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; import com.powsybl.diagram.test.Networks; -import com.powsybl.iidm.network.Network; import com.powsybl.sld.builders.NetworkGraphBuilder; import com.powsybl.sld.library.ComponentSize; import com.powsybl.sld.model.coordinate.Direction; -import com.powsybl.sld.model.nodes.SwitchNode; -import com.powsybl.sld.model.nodes.Node; import com.powsybl.sld.model.graphs.SubstationGraph; import com.powsybl.sld.model.graphs.VoltageLevelGraph; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; +import com.powsybl.sld.model.nodes.Node; +import com.powsybl.sld.model.nodes.SwitchNode; +import com.powsybl.sld.svg.DefaultLabelProvider; import com.powsybl.sld.svg.LabelPosition; +import com.powsybl.sld.svg.LabelProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -48,11 +49,34 @@ void testBranchStatusDecorators() { substationGraphLayout(g); assertEquals(toString("/NodeDecoratorsBranchStatusNodeBreaker.svg"), - toSVG(g, "/NodeDecoratorsBranchStatusNodeBreaker.svg", getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); + toSVG(g, "/NodeDecoratorsBranchStatusNodeBreaker.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } @Test void testSwitchDecorators() { + + LabelProvider labelTestProvider = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters) { + + private static final double SWITCH_DECORATOR_OFFSET = 1d; + + @Override + public List getNodeDecorators(Node node, Direction direction) { + Objects.requireNonNull(node); + if (node instanceof SwitchNode) { + return Collections.singletonList(new NodeDecorator("LOCK", getSwitchDecoratorPosition((SwitchNode) node))); + } + return Collections.emptyList(); + } + + private LabelPosition getSwitchDecoratorPosition(SwitchNode node) { + ComponentSize size = componentLibrary.getSize(node.getComponentType()); + double yShift = -size.getHeight() / 2; + double xShift = size.getWidth() / 2 + SWITCH_DECORATOR_OFFSET; + return new LabelPosition("DECORATOR", xShift, yShift, false, 0); + } + + }; + // build graph VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(network.getVoltageLevel("VL1").getId()); @@ -61,31 +85,7 @@ void testSwitchDecorators() { // write SVG and compare to reference assertEquals(toString("/NodeDecoratorsSwitches.svg"), - toSVG(g, "/NodeDecoratorsSwitches.svg", new TestDiagramLabelProvider(network), getDefaultDiagramStyleProvider())); + toSVG(g, "/NodeDecoratorsSwitches.svg", componentLibrary, layoutParameters, svgParameters, labelTestProvider, getDefaultDiagramStyleProvider())); } - private class TestDiagramLabelProvider extends DefaultDiagramLabelProvider { - - private static final double SWITCH_DECORATOR_OFFSET = 1d; - - public TestDiagramLabelProvider(Network network) { - super(network, TestNodeDecoratorsNodeBreaker.this.componentLibrary, TestNodeDecoratorsNodeBreaker.this.layoutParameters); - } - - @Override - public List getNodeDecorators(Node node, Direction direction) { - Objects.requireNonNull(node); - if (node instanceof SwitchNode) { - return Collections.singletonList(new NodeDecorator("LOCK", getSwitchDecoratorPosition((SwitchNode) node))); - } - return Collections.emptyList(); - } - - private LabelPosition getSwitchDecoratorPosition(SwitchNode node) { - ComponentSize size = componentLibrary.getSize(node.getComponentType()); - double yShift = -size.getHeight() / 2; - double xShift = size.getWidth() / 2 + SWITCH_DECORATOR_OFFSET; - return new LabelPosition("DECORATOR", xShift, yShift, false, 0); - } - } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java index 4a6fa4598..422c63ce8 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java @@ -3,12 +3,12 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; import com.powsybl.iidm.network.Branch.Side; import com.powsybl.iidm.network.Network; -import com.powsybl.sld.layout.LayoutParameters; import com.powsybl.sld.library.ComponentTypeName; import com.powsybl.sld.model.coordinate.Direction; import com.powsybl.sld.model.coordinate.Orientation; @@ -59,8 +59,10 @@ class TestSVGWriter extends AbstractTestCaseIidm { private VoltageLevelGraph g2; private VoltageLevelGraph g3; private SubstationGraph substG; - private DiagramLabelProvider labelProvider; - private DiagramLabelProvider noFeederInfoProvider; + private LabelProvider labelProvider; + private LabelProvider labelNoFeederInfoProvider; + private LabelProvider diagramLabelMultiLineTooltipProvider; + private LabelProvider diagramLabelSameNodeProvider; private ZoneGraph zGraph; private void createVoltageLevelGraphs() { @@ -590,18 +592,18 @@ public void setUp() { createZoneGraph(); // Layout parameters : - layoutParameters.setShowGrid(false); // grid is only for SVG generated with a CellDetector + svgParameters.setShowGrid(false); // grid is only for SVG generated with a CellDetector // initValueProvider example for the test : // - labelProvider = new DefaultDiagramLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters) { + labelProvider = new DefaultLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters, svgParameters) { @Override public List getFeederInfos(FeederNode node) { List feederInfos = Arrays.asList( new DirectionalFeederInfo(ARROW_ACTIVE, LabelDirection.OUT, null, "10", null), new DirectionalFeederInfo(ARROW_REACTIVE, LabelDirection.IN, null, "20", null)); - boolean feederArrowSymmetry = node.getDirection() == TOP || layoutParameters.isFeederInfoSymmetry(); + boolean feederArrowSymmetry = node.getDirection() == TOP || svgParameters.isFeederInfoSymmetry(); if (!feederArrowSymmetry) { Collections.reverse(feederInfos); } @@ -609,21 +611,54 @@ public List getFeederInfos(FeederNode node) { } @Override - public List getNodeDecorators(Node node, Direction direction) { + public List getNodeDecorators(Node node, Direction direction) { return new ArrayList<>(); } }; // no feeder value provider example for the test : - // - noFeederInfoProvider = new DefaultDiagramLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters) { + labelNoFeederInfoProvider = new DefaultLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters, svgParameters) { + @Override public List getFeederInfos(FeederNode node) { return Collections.emptyList(); } @Override - public List getNodeDecorators(Node node, Direction direction) { + public List getNodeDecorators(Node node, Direction direction) { + return new ArrayList<>(); + } + }; + + // no feeder value provider example for the test : + // + diagramLabelMultiLineTooltipProvider = new DefaultLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters, svgParameters) { + + @Override + public String getTooltip(Node node) { + String tooltip = node.getId(); + if (node.getType() == Node.NodeType.FEEDER) { + tooltip += "\n" + node.getComponentType(); + } + return tooltip; + } + + @Override + public List getNodeDecorators(Node node, Direction direction) { + return Collections.emptyList(); + } + }; + + diagramLabelSameNodeProvider = new DefaultLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters, svgParameters) { + + @Override + public List getNodeLabels(Node node, Direction direction) { + LabelPosition labelPosition = new LabelPosition("default", 0, -5, true, 0); + return Collections.singletonList(new LabelProvider.NodeLabel("Tests", labelPosition, null)); + } + + @Override + public List getNodeDecorators(Node node, Direction direction) { return new ArrayList<>(); } }; @@ -632,154 +667,135 @@ public List getNodeDecorators(Node node, Dir @Test void testVl1() { assertEquals(toString("/vl1.svg"), - toSVG(g1, "/vl1.svg", labelProvider, new BasicStyleProvider())); + toSVG(g1, "/vl1.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testVl1CssExternalImported() { - layoutParameters.setCssLocation(LayoutParameters.CssLocation.EXTERNAL_IMPORTED); + svgParameters.setCssLocation(SvgParameters.CssLocation.EXTERNAL_IMPORTED); + assertEquals(toString("/vl1_external_css.svg"), - toSVG(g1, "/vl1_external_css.svg", labelProvider, new BasicStyleProvider())); + toSVG(g1, "/vl1_external_css.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testVl1CssExternalNoImport() { - layoutParameters.setCssLocation(LayoutParameters.CssLocation.EXTERNAL_NO_IMPORT); + svgParameters.setCssLocation(SvgParameters.CssLocation.EXTERNAL_NO_IMPORT); + assertEquals(toString("/vl1_external_css_no_import.svg"), - toSVG(g1, "/vl1_external_css_no_import.svg", labelProvider, new BasicStyleProvider())); + toSVG(g1, "/vl1_external_css_no_import.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testVl2() { assertEquals(toString("/vl2.svg"), - toSVG(g2, "/vl2.svg", labelProvider, new BasicStyleProvider())); + toSVG(g2, "/vl2.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testVl3() { assertEquals(toString("/vl3.svg"), - toSVG(g3, "/vl3.svg", labelProvider, new BasicStyleProvider())); + toSVG(g3, "/vl3.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testSubstation() { // SVG file generation for substation and comparison to reference assertEquals(toString("/substation.svg"), - toSVG(substG, "/substation.svg", labelProvider, new NominalVoltageStyleProvider())); + toSVG(substG, "/substation.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new NominalVoltageStyleProvider())); } @Test void testSubstationArrowSymmetry() { // SVG file generation for substation with symmetric feeder arrow and comparison to reference - layoutParameters.setFeederInfoSymmetry(true); + svgParameters.setFeederInfoSymmetry(true); assertEquals(toString("/substation_feeder_arrow_symmetry.svg"), - toSVG(substG, "/substation_feeder_arrow_symmetry.svg", labelProvider, new BasicStyleProvider())); + toSVG(substG, "/substation_feeder_arrow_symmetry.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testSubstationNoFeederInfos() { // SVG file generation for substation and comparison to reference but with no feeder values assertEquals(toString("/substation_no_feeder_values.svg"), - toSVG(substG, "/substation_no_feeder_values.svg", noFeederInfoProvider, new BasicStyleProvider())); + toSVG(substG, "/substation_no_feeder_values.svg", componentLibrary, layoutParameters, svgParameters, labelNoFeederInfoProvider, new BasicStyleProvider())); } @Test void testVl1Optimized() { // Same tests than before, with optimized svg - layoutParameters.setAvoidSVGComponentsDuplication(true); + svgParameters.setAvoidSVGComponentsDuplication(true); + assertEquals(toString("/vl1_optimized.svg"), - toSVG(g1, "/vl1_optimized.svg", labelProvider, new BasicStyleProvider())); + toSVG(g1, "/vl1_optimized.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testVl2Optimized() { // Same tests than before, with optimized svg - layoutParameters.setAvoidSVGComponentsDuplication(true); + svgParameters.setAvoidSVGComponentsDuplication(true); + assertEquals(toString("/vl2_optimized.svg"), - toSVG(g2, "/vl2_optimized.svg", labelProvider, new BasicStyleProvider())); + toSVG(g2, "/vl2_optimized.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testVl3Optimized() { // Same tests than before, with optimized svg - layoutParameters.setAvoidSVGComponentsDuplication(true); + svgParameters.setAvoidSVGComponentsDuplication(true); + assertEquals(toString("/vl3_optimized.svg"), - toSVG(g3, "/vl3_optimized.svg", labelProvider, new BasicStyleProvider())); + toSVG(g3, "/vl3_optimized.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testSubstationOptimized() { // Same tests than before, with optimized svg - layoutParameters.setAvoidSVGComponentsDuplication(true); + svgParameters.setAvoidSVGComponentsDuplication(true); + assertEquals(toString("/substation_optimized.svg"), - toSVG(substG, "/substation_optimized.svg", labelProvider, new BasicStyleProvider())); + toSVG(substG, "/substation_optimized.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testWriteZone() { - layoutParameters.setShowGrid(false); + svgParameters.setShowGrid(false); + assertEquals(toString("/zone.svg"), - toSVG(zGraph, "/zone.svg", labelProvider, new BasicStyleProvider())); + toSVG(zGraph, "/zone.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testStraightWires() { - StyleProvider styleProvider = new BasicStyleProvider(); - layoutParameters.setDrawStraightWires(true); + svgParameters.setDrawStraightWires(true); + assertEquals(toString("/vl1_straightWires.svg"), - toSVG(g1, "/vl1_straightWires.svg", labelProvider, styleProvider)); + toSVG(g1, "/vl1_straightWires.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testTooltip() { - layoutParameters.setTooltipEnabled(true); + svgParameters.setTooltipEnabled(true); + assertEquals(toString("/vl1_tooltip.svg"), - toSVG(g1, "/vl1_tooltip.svg", labelProvider, new BasicStyleProvider())); + toSVG(g1, "/vl1_tooltip.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, new BasicStyleProvider())); } @Test void testMultiLineTooltip() { - DiagramLabelProvider labelProvider = new DefaultDiagramLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters) { - @Override - public String getTooltip(Node node) { - String tooltip = node.getId(); - if (node.getType() == Node.NodeType.FEEDER) { - tooltip += "\n" + node.getComponentType(); - } - return tooltip; - } - @Override - public List getNodeDecorators(Node node, Direction direction) { - return Collections.emptyList(); - } - }; - layoutParameters.setAvoidSVGComponentsDuplication(true); - layoutParameters.setTooltipEnabled(true); + svgParameters.setAvoidSVGComponentsDuplication(true); + svgParameters.setTooltipEnabled(true); + assertEquals(toString("/vl1_multiline_tooltip.svg"), - toSVG(g1, "/vl1_multiline_tooltip.svg", labelProvider, new BasicStyleProvider())); + toSVG(g1, "/vl1_multiline_tooltip.svg", componentLibrary, layoutParameters, svgParameters, diagramLabelMultiLineTooltipProvider, new BasicStyleProvider())); } @Test void testLabelOnAllNodes() { // same node label provider example for the test : - // - DiagramLabelProvider sameNodeLabelProvider = new DefaultDiagramLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters) { - @Override - public List getNodeLabels(Node node, Direction direction) { - LabelPosition labelPosition = new LabelPosition("default", 0, -5, true, 0); - return Collections.singletonList(new DiagramLabelProvider.NodeLabel("Tests", labelPosition, null)); - } - - @Override - public List getNodeDecorators(Node node, Direction direction) { - return new ArrayList<>(); - } - }; - StyleProvider styleProvider = new BasicStyleProvider(); assertEquals(toString("/label_on_all_nodes.svg"), - toSVG(g1, "/label_on_all_nodes.svg", sameNodeLabelProvider, styleProvider)); + toSVG(g1, "/label_on_all_nodes.svg", componentLibrary, layoutParameters, svgParameters, diagramLabelSameNodeProvider, new BasicStyleProvider())); } @Test @@ -790,7 +806,8 @@ public List getCssFilenames() { return Arrays.asList("tautologies.css", "baseVoltages.css", "highlightLineStates.css", "TestWithGreyFrameBackground.css"); } }; + assertEquals(toString("/with_frame_background.svg"), - toSVG(g1, "/with_frame_background.svg", labelProvider, styleProvider)); + toSVG(g1, "/with_frame_background.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, styleProvider)); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSingleLineDiagramClass.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSingleLineDiagramClass.java index d0962f575..d3b28e67f 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSingleLineDiagramClass.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSingleLineDiagramClass.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -12,8 +13,11 @@ import com.powsybl.diagram.test.Networks; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ConnectablePosition; +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; @@ -26,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; @@ -80,7 +86,8 @@ void testSvgVl1() throws IOException { assertEquals(expected, toDefaultSVG(network, vl.getId(), "/TestSldClassVl.svg", "/TestSldClassVlMetadata.json")); Writer writerForSvg = new StringWriter(); - SingleLineDiagram.drawVoltageLevel(network, vl.getId(), writerForSvg, new NullWriter()); + + SingleLineDiagram.drawVoltageLevel(network, vl.getId(), writerForSvg, new NullWriter(), new SldParameters()); assertEquals(expected, normalizeLineSeparator(writerForSvg.toString())); Path svgPath = tmpDir.resolve("result.svg"); @@ -121,7 +128,8 @@ void testSvgSubs() throws IOException { } Writer writerForSvg = new StringWriter(); - SingleLineDiagram.drawSubstation(network, substation.getId(), writerForSvg, new NullWriter()); + + SingleLineDiagram.drawSubstation(network, substation.getId(), writerForSvg, new NullWriter(), new SldParameters()); assertEquals(expected, normalizeLineSeparator(writerForSvg.toString())); Path svgPath = tmpDir.resolve("result.svg"); @@ -145,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 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()) { diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestTieLine.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestTieLine.java index d4964f4ae..3a586de54 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestTieLine.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestTieLine.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -13,7 +14,7 @@ import com.powsybl.sld.layout.VerticalSubstationLayoutFactory; import com.powsybl.sld.model.graphs.SubstationGraph; import com.powsybl.sld.model.graphs.VoltageLevelGraph; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; +import com.powsybl.sld.svg.DefaultLabelProvider; import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider; import org.junit.jupiter.api.Test; @@ -41,7 +42,7 @@ void testTieLineInVoltageLevel() { new SmartVoltageLevelLayoutFactory(network).create(g).run(layoutParameters); // write SVG and compare to reference - assertEquals(toString("/TestTieLineVoltageLevel.svg"), toSVG(g, "/TestTieLineVoltageLevel.svg", new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), new TopologicalStyleProvider(network))); + assertEquals(toString("/TestTieLineVoltageLevel.svg"), toSVG(g, "/TestTieLineVoltageLevel.svg", componentLibrary, layoutParameters, svgParameters, new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters), new TopologicalStyleProvider(network))); } @Test @@ -55,7 +56,7 @@ void testTieLineInSubstation() { new VerticalSubstationLayoutFactory().create(g, new SmartVoltageLevelLayoutFactory(network)).run(layoutParameters); // write SVG and compare to reference - assertEquals(toString("/TestTieLineSubstation.svg"), toSVG(g, "/TestTieLineSubstation.svg", new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters), new TopologicalStyleProvider(network))); + assertEquals(toString("/TestTieLineSubstation.svg"), toSVG(g, "/TestTieLineSubstation.svg", componentLibrary, layoutParameters, svgParameters, new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters), new TopologicalStyleProvider(network))); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnicityNodeIdWithMutipleNetwork.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnicityNodeIdWithMutipleNetwork.java index 3aa8c4cf2..bf4501c8a 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnicityNodeIdWithMutipleNetwork.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnicityNodeIdWithMutipleNetwork.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.iidm; @@ -11,8 +12,8 @@ import com.powsybl.iidm.network.extensions.ConnectablePosition; import com.powsybl.sld.builders.GraphBuilder; import com.powsybl.sld.builders.NetworkGraphBuilder; -import com.powsybl.sld.layout.LayoutParameters; import com.powsybl.sld.model.graphs.VoltageLevelGraph; +import com.powsybl.sld.svg.SvgParameters; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,9 +31,8 @@ class TestUnicityNodeIdWithMutipleNetwork extends AbstractTestCaseIidm { @BeforeEach public void setUp() { - layoutParameters - .setAdaptCellHeightToContent(false) - .setCssLocation(LayoutParameters.CssLocation.INSERTED_IN_SVG); + layoutParameters.setAdaptCellHeightToContent(false); + svgParameters.setCssLocation(SvgParameters.CssLocation.INSERTED_IN_SVG); // Create first network with a substation and a voltageLevel network = Network.create("n1", "test"); diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnknownComponent.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnknownComponent.java index e86f11a96..63aa69d44 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnknownComponent.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestUnknownComponent.java @@ -37,7 +37,7 @@ protected ResourcesComponentLibrary getResourcesComponentLibrary() { @Test void test() { - layoutParameters.setAddNodesInfos(true); + svgParameters.setAddNodesInfos(true); // build voltage level 1 graph VoltageLevelGraph g1 = graphBuilder.buildVoltageLevelGraph("vl1"); @@ -45,6 +45,6 @@ void test() { voltageLevelGraphLayout(g1); // write SVGs and compare to reference - assertEquals(toString("/TestUnknownLibrary.svg"), toSVG(g1, "/TestUnknownLibrary.svg")); + assertEquals(toString("/TestUnknownLibrary.svg"), toSVG(g1, "/TestUnknownLibrary.svg", getResourcesComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestViewBox.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestViewBox.java index 47fe5b526..162a30fe2 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestViewBox.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestViewBox.java @@ -36,7 +36,7 @@ void test(String suffix) { substation = network.getSubstation("ST"); graphBuilder = new NetworkGraphBuilder(network); - layoutParameters.setShowGrid(true); + svgParameters.setShowGrid(true); // build substation ST graph SubstationGraph g1 = graphBuilder.buildSubstationGraph("ST"); diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/ComponentsOnBusTest.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/ComponentsOnBusTest.java index 8c6b660c7..209b53c91 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/ComponentsOnBusTest.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/ComponentsOnBusTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.layout; @@ -36,7 +37,8 @@ void testNoComponentsOnBuses() { layoutParameters.setComponentsOnBusbars(Collections.emptyList()); VoltageLevelGraph vlg = graphBuilder.buildVoltageLevelGraph(vl.getId()); voltageLevelGraphLayout(vlg); - assertEquals(toString("/noComponentsOnBus.svg"), toSVG(vlg, "/noComponentsOnBus.svg")); + + assertEquals(toString("/noComponentsOnBus.svg"), toSVG(vlg, "/noComponentsOnBus.svg", getResourcesComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } @Test @@ -44,6 +46,7 @@ void testSwitchesOnBuses() { layoutParameters.setComponentsOnBusbars(List.of(ComponentTypeName.BREAKER, ComponentTypeName.DISCONNECTOR)); VoltageLevelGraph vlg = graphBuilder.buildVoltageLevelGraph(vl.getId()); voltageLevelGraphLayout(vlg); - assertEquals(toString("/switchesOnBus.svg"), toSVG(vlg, "/switchesOnBus.svg")); + + assertEquals(toString("/switchesOnBus.svg"), toSVG(vlg, "/switchesOnBus.svg", getResourcesComponentLibrary(), layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java index 2be03f9f0..43ddec8cf 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.layout; @@ -22,103 +23,59 @@ class LayoutParametersTest { @Test void test() { LayoutParameters layoutParameters = new LayoutParameters() - .setVoltageLevelPadding(15, 35, 25, 45) - .setDiagrammPadding(20, 40, 30, 50) .setVerticalSpaceBus(20) .setHorizontalBusPadding(30) .setCellWidth(70) .setExternCellHeight(240) .setInternCellHeight(50) .setStackHeight(40) - .setShowGrid(true) - .setShowInternalNodes(true) - .setScaleFactor(2) - .setDrawStraightWires(true) .setHorizontalSnakeLinePadding(25) .setVerticalSnakeLinePadding(40) - .setFeederInfosOuterMargin(25) - .setDiagramName("diag") - .setAvoidSVGComponentsDuplication(true) + .setSpaceForFeederInfos(70) .setAdaptCellHeightToContent(true) .setMaxComponentHeight(10) .setMinSpaceBetweenComponents(30) .setMinExternCellHeight(150) - .setAngleLabelShift(42) - .setLabelCentered(true) - .setLabelDiagonal(true) - .setTooltipEnabled(true) - .setAddNodesInfos(true) - .setSpaceForFeederInfos(70) - .setFeederInfoSymmetry(true) - .setCssLocation(LayoutParameters.CssLocation.EXTERNAL_NO_IMPORT) - .setSvgWidthAndHeightAdded(true) - .setUseName(true) - .setFeederInfosIntraMargin(21) - .setBusInfoMargin(22) + .setVoltageLevelPadding(15, 35, 25, 45) + .setDiagrammPadding(20, 40, 30, 50) .setBusbarsAlignment(LayoutParameters.Alignment.LAST) .setComponentsOnBusbars(List.of("COMPONENT_ON_BUS")) - .setLanguageTag("fr") - .setVoltageValuePrecision(3) - .setPowerValuePrecision(2) - .setAngleValuePrecision(0) - .setUndefinedValueSymbol("\u002A") - .setDisplayCurrentFeederInfo(true) - .setCurrentValuePrecision(1) - .setRemoveFictitiousSwitchNodes(true); + .setRemoveFictitiousSwitchNodes(true) + .setCgmesScaleFactor(2) + .setCgmesDiagramName("diag") + .setCgmesUseNames(true); layoutParameters.setComponentsSize(null); LayoutParameters layoutParameters2 = new LayoutParameters(layoutParameters); - assertEquals(layoutParameters.getVoltageLevelPadding().getLeft(), layoutParameters2.getVoltageLevelPadding().getLeft(), 0); - assertEquals(layoutParameters.getVoltageLevelPadding().getTop(), layoutParameters2.getVoltageLevelPadding().getTop(), 0); - assertEquals(layoutParameters.getVoltageLevelPadding().getRight(), layoutParameters2.getVoltageLevelPadding().getRight(), 0); - assertEquals(layoutParameters.getVoltageLevelPadding().getBottom(), layoutParameters2.getVoltageLevelPadding().getBottom(), 0); - assertEquals(layoutParameters.getDiagramPadding().getLeft(), layoutParameters2.getDiagramPadding().getLeft(), 0); - assertEquals(layoutParameters.getDiagramPadding().getTop(), layoutParameters2.getDiagramPadding().getTop(), 0); - assertEquals(layoutParameters.getDiagramPadding().getRight(), layoutParameters2.getDiagramPadding().getRight(), 0); - assertEquals(layoutParameters.getDiagramPadding().getBottom(), layoutParameters2.getDiagramPadding().getBottom(), 0); assertEquals(layoutParameters.getVerticalSpaceBus(), layoutParameters2.getVerticalSpaceBus(), 0); assertEquals(layoutParameters.getHorizontalBusPadding(), layoutParameters2.getHorizontalBusPadding(), 0); assertEquals(layoutParameters.getCellWidth(), layoutParameters2.getCellWidth(), 0); assertEquals(layoutParameters.getExternCellHeight(), layoutParameters2.getExternCellHeight(), 0); assertEquals(layoutParameters.getInternCellHeight(), layoutParameters2.getInternCellHeight(), 0); assertEquals(layoutParameters.getStackHeight(), layoutParameters2.getStackHeight(), 0); - assertEquals(layoutParameters.isShowGrid(), layoutParameters2.isShowGrid()); - assertEquals(layoutParameters.isShowInternalNodes(), layoutParameters2.isShowInternalNodes()); - assertEquals(layoutParameters.getScaleFactor(), layoutParameters2.getScaleFactor(), 0); - assertEquals(layoutParameters.isDrawStraightWires(), layoutParameters2.isDrawStraightWires()); assertEquals(layoutParameters.getHorizontalSnakeLinePadding(), layoutParameters2.getHorizontalSnakeLinePadding(), 0); assertEquals(layoutParameters.getVerticalSnakeLinePadding(), layoutParameters2.getVerticalSnakeLinePadding(), 0); - assertEquals(layoutParameters.getFeederInfosOuterMargin(), layoutParameters2.getFeederInfosOuterMargin(), 0); - assertEquals(layoutParameters.getDiagramName(), layoutParameters2.getDiagramName()); - assertEquals(layoutParameters.isAvoidSVGComponentsDuplication(), layoutParameters2.isAvoidSVGComponentsDuplication()); + assertEquals(layoutParameters.getSpaceForFeederInfos(), layoutParameters2.getSpaceForFeederInfos(), 0); assertEquals(layoutParameters.isAdaptCellHeightToContent(), layoutParameters2.isAdaptCellHeightToContent()); assertEquals(layoutParameters.getMaxComponentHeight(), layoutParameters2.getMaxComponentHeight(), 0); assertEquals(layoutParameters.getMinSpaceBetweenComponents(), layoutParameters2.getMinSpaceBetweenComponents(), 0); assertEquals(layoutParameters.getMinExternCellHeight(), layoutParameters2.getMinExternCellHeight(), 0); - assertEquals(layoutParameters.getAngleLabelShift(), layoutParameters2.getAngleLabelShift(), 0); - assertEquals(layoutParameters.isLabelCentered(), layoutParameters2.isLabelCentered()); - assertEquals(layoutParameters.isLabelDiagonal(), layoutParameters2.isLabelDiagonal()); - assertEquals(layoutParameters.isTooltipEnabled(), layoutParameters2.isTooltipEnabled()); - assertEquals(layoutParameters.isAddNodesInfos(), layoutParameters2.isAddNodesInfos()); - assertEquals(layoutParameters.getSpaceForFeederInfos(), layoutParameters2.getSpaceForFeederInfos(), 0); - assertEquals(layoutParameters.isFeederInfoSymmetry(), layoutParameters2.isFeederInfoSymmetry()); - assertEquals(layoutParameters.getCssLocation(), layoutParameters2.getCssLocation()); - assertEquals(layoutParameters.isSvgWidthAndHeightAdded(), layoutParameters2.isSvgWidthAndHeightAdded()); - assertEquals(layoutParameters.isUseName(), layoutParameters2.isUseName()); - assertEquals(layoutParameters.getFeederInfosIntraMargin(), layoutParameters2.getFeederInfosIntraMargin(), 0); - assertEquals(layoutParameters.getBusInfoMargin(), layoutParameters2.getBusInfoMargin(), 0); + assertEquals(layoutParameters.getVoltageLevelPadding().getLeft(), layoutParameters2.getVoltageLevelPadding().getLeft(), 0); + assertEquals(layoutParameters.getVoltageLevelPadding().getTop(), layoutParameters2.getVoltageLevelPadding().getTop(), 0); + assertEquals(layoutParameters.getVoltageLevelPadding().getRight(), layoutParameters2.getVoltageLevelPadding().getRight(), 0); + assertEquals(layoutParameters.getVoltageLevelPadding().getBottom(), layoutParameters2.getVoltageLevelPadding().getBottom(), 0); + assertEquals(layoutParameters.getDiagramPadding().getLeft(), layoutParameters2.getDiagramPadding().getLeft(), 0); + assertEquals(layoutParameters.getDiagramPadding().getTop(), layoutParameters2.getDiagramPadding().getTop(), 0); + assertEquals(layoutParameters.getDiagramPadding().getRight(), layoutParameters2.getDiagramPadding().getRight(), 0); + assertEquals(layoutParameters.getDiagramPadding().getBottom(), layoutParameters2.getDiagramPadding().getBottom(), 0); assertEquals(layoutParameters.getBusbarsAlignment(), layoutParameters2.getBusbarsAlignment()); assertEquals(layoutParameters.getComponentsOnBusbars(), layoutParameters2.getComponentsOnBusbars()); - assertEquals(layoutParameters.getLanguageTag(), layoutParameters2.getLanguageTag()); - assertEquals(layoutParameters.getVoltageValuePrecision(), layoutParameters2.getVoltageValuePrecision()); - assertEquals(layoutParameters.getPowerValuePrecision(), layoutParameters2.getPowerValuePrecision()); - assertEquals(layoutParameters.getAngleValuePrecision(), layoutParameters2.getAngleValuePrecision()); - assertEquals(layoutParameters.getCurrentValuePrecision(), layoutParameters2.getCurrentValuePrecision()); - assertEquals(layoutParameters.isDisplayCurrentFeederInfo(), layoutParameters2.isDisplayCurrentFeederInfo()); - assertEquals(layoutParameters.getUndefinedValueSymbol(), layoutParameters2.getUndefinedValueSymbol()); - assertEquals(layoutParameters.getComponentsSize(), layoutParameters2.getComponentsSize()); assertEquals(layoutParameters.isRemoveFictitiousSwitchNodes(), layoutParameters2.isRemoveFictitiousSwitchNodes()); + assertEquals(layoutParameters.getComponentsSize(), layoutParameters2.getComponentsSize()); + assertEquals(layoutParameters.getCgmesScaleFactor(), layoutParameters2.getCgmesScaleFactor(), 0); + assertEquals(layoutParameters.getCgmesDiagramName(), layoutParameters2.getCgmesDiagramName()); + assertEquals(layoutParameters.isCgmesUseNames(), layoutParameters2.isCgmesUseNames()); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/AbstractTestCaseRaw.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/AbstractTestCaseRaw.java index 7cf8be39e..fcbd1a020 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/AbstractTestCaseRaw.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/AbstractTestCaseRaw.java @@ -3,21 +3,26 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.raw; +import com.powsybl.iidm.network.Network; import com.powsybl.sld.AbstractTestCase; import com.powsybl.sld.builders.RawGraphBuilder; -import com.powsybl.sld.layout.LayoutParameters; -import com.powsybl.sld.library.ComponentLibrary; import com.powsybl.sld.model.coordinate.Direction; import com.powsybl.sld.model.graphs.Graph; import com.powsybl.sld.model.nodes.FeederNode; import com.powsybl.sld.model.nodes.Node; -import com.powsybl.sld.svg.*; +import com.powsybl.sld.svg.DefaultLabelProvider; +import com.powsybl.sld.svg.DirectionalFeederInfo; +import com.powsybl.sld.svg.FeederInfo; +import com.powsybl.sld.svg.LabelProvider; import com.powsybl.sld.svg.styles.BasicStyleProvider; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import static com.powsybl.sld.library.ComponentTypeName.ARROW_ACTIVE; import static com.powsybl.sld.library.ComponentTypeName.ARROW_REACTIVE; @@ -28,19 +33,12 @@ public abstract class AbstractTestCaseRaw extends AbstractTestCase { protected RawGraphBuilder rawGraphBuilder = new RawGraphBuilder(); - protected RawDiagramLabelProvider getRawLabelProvider() { - return new RawDiagramLabelProvider(componentLibrary, layoutParameters); - } - @Override public String toSVG(Graph graph, String filename) { - return toSVG(graph, filename, getRawLabelProvider(), new BasicStyleProvider()); + return toSVG(graph, filename, componentLibrary, layoutParameters, svgParameters, labelRawProvider, new BasicStyleProvider()); } - private static class RawDiagramLabelProvider extends AbstractDiagramLabelProvider { - public RawDiagramLabelProvider(ComponentLibrary componentLibrary, LayoutParameters layoutParameters) { - super(componentLibrary, layoutParameters); - } + private final LabelProvider labelRawProvider = new DefaultLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters, svgParameters) { @Override public List getFeederInfos(FeederNode node) { @@ -53,5 +51,9 @@ public List getFeederInfos(FeederNode node) { public List getNodeDecorators(Node node, Direction direction) { return new ArrayList<>(); } + }; + + public LabelProvider getLabelRawProvider() { + return labelRawProvider; } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddBatteries.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddBatteries.java index 84117b8e1..9bae5770d 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddBatteries.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddBatteries.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.raw; @@ -53,6 +54,6 @@ void test() { VoltageLevelGraph g = rawGraphBuilder.buildVoltageLevelGraph("vl"); voltageLevelGraphLayout(g); assertEquals(toString("/TestBatteriesRaw.svg"), - toSVG(g, "/TestBatteriesRaw.svg", getRawLabelProvider(), new BasicStyleProvider())); + toSVG(g, "/TestBatteriesRaw.svg", getResourcesComponentLibrary(), layoutParameters, svgParameters, getLabelRawProvider(), new BasicStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddExternalComponent.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddExternalComponent.java index 2ae54581e..e4a24dea4 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddExternalComponent.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestAddExternalComponent.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.raw; @@ -51,6 +52,6 @@ void test() { VoltageLevelGraph g = rawGraphBuilder.buildVoltageLevelGraph("vl"); voltageLevelGraphLayout(g); assertEquals(toString("/TestCheese.svg"), - toSVG(g, "/TestCheese.svg", getRawLabelProvider(), new BasicStyleProvider())); + toSVG(g, "/TestCheese.svg", getResourcesComponentLibrary(), layoutParameters, svgParameters, getLabelRawProvider(), new BasicStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCase1.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCase1.java index 90edc59a5..5999b4ee0 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCase1.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCase1.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.raw; @@ -49,7 +50,8 @@ public void setUp() { void test() { VoltageLevelGraph g = rawGraphBuilder.buildVoltageLevelGraph("vl"); voltageLevelGraphLayout(g); + assertEquals(toString("/TestCase1.svg"), - toSVG(g, "/TestCase1.svg", getRawLabelProvider(), new BasicStyleProvider())); + toSVG(g, "/TestCase1.svg", getResourcesComponentLibrary(), layoutParameters, svgParameters, getLabelRawProvider(), new BasicStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCaseComplexCoupling.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCaseComplexCoupling.java index a9c86622c..8dc63428d 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCaseComplexCoupling.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestCaseComplexCoupling.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.raw; @@ -55,6 +56,6 @@ void test() { voltageLevelGraphLayout(g); - assertEquals(toString("/TestCaseComplexCoupling.svg"), toSVG(g, "/TestCaseComplexCoupling.svg", getRawLabelProvider(), new BasicStyleProvider())); + assertEquals(toString("/TestCaseComplexCoupling.svg"), toSVG(g, "/TestCaseComplexCoupling.svg", componentLibrary, layoutParameters, svgParameters, getLabelRawProvider(), new BasicStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestInsertFictitiousNodesAtFeeder.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestInsertFictitiousNodesAtFeeder.java index 88e64af45..ff1e65673 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestInsertFictitiousNodesAtFeeder.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/raw/TestInsertFictitiousNodesAtFeeder.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.raw; @@ -52,7 +53,8 @@ void testFeederOnBus() { vlBuilder.connectNode(bbs, feederLineNode); VoltageLevelGraph g = rawGraphBuilder.buildVoltageLevelGraph("vl"); voltageLevelGraphLayout(g); - assertEquals(toString("/TestFeederOnBus.svg"), toSVG(g, "/TestFeederOnBus.svg", getRawLabelProvider(), new BasicStyleProvider())); + + assertEquals(toString("/TestFeederOnBus.svg"), toSVG(g, "/TestFeederOnBus.svg", componentLibrary, layoutParameters, svgParameters, getLabelRawProvider(), new BasicStyleProvider())); } @Test @@ -65,6 +67,7 @@ void testFeederOnBusDisconnector() { vlBuilder.connectNode(busDisconnector, feederLineNode); VoltageLevelGraph g = rawGraphBuilder.buildVoltageLevelGraph("vl"); voltageLevelGraphLayout(g); - assertEquals(toString("/TestFeederOnBusDisconnector.svg"), toSVG(g, "/TestFeederOnBusDisconnector.svg", getRawLabelProvider(), new BasicStyleProvider())); + + assertEquals(toString("/TestFeederOnBusDisconnector.svg"), toSVG(g, "/TestFeederOnBusDisconnector.svg", componentLibrary, layoutParameters, svgParameters, getLabelRawProvider(), new BasicStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java index e223a0af0..b06506296 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -43,19 +44,20 @@ public void setUp() { @Test void test() { ComponentLibrary componentLibrary = new ConvergenceComponentLibrary(); - layoutParameters.setFeederInfoSymmetry(true); + svgParameters.setFeederInfoSymmetry(true); // build first voltage level graph VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId()); voltageLevelGraphLayout(g); // to have cell orientations (bottom / up) - assertEquals(toString("/feederInfoTest.svg"), toSVG(g, "/feederInfoTest.svg")); + + assertEquals(toString("/feederInfoTest.svg"), toSVG(g, "/feederInfoTest.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); Network network2 = Network.create("testCase2", "test2"); - DefaultDiagramLabelProvider wrongLabelProvider = new DefaultDiagramLabelProvider(network2, componentLibrary, layoutParameters); + DefaultLabelProvider wrongLabelProvider = new DefaultLabelProvider(network2, componentLibrary, layoutParameters, svgParameters); List feederInfos = wrongLabelProvider.getFeederInfos((FeederNode) g.getNode("svc")); assertTrue(feederInfos.isEmpty()); - DefaultDiagramLabelProvider labelProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters); + DefaultLabelProvider labelProvider = new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters); List feederInfos1 = labelProvider.getFeederInfos((FeederNode) g.getNode("svc")); assertEquals(2, feederInfos1.size()); assertEquals(ARROW_ACTIVE, feederInfos1.get(0).getComponentType()); @@ -106,7 +108,7 @@ void test() { assertFalse(feederInfos4.get(1).getLeftLabel().isPresent()); // Reverse order - layoutParameters.setFeederInfoSymmetry(false); + svgParameters.setFeederInfoSymmetry(false); List feederInfos5 = labelProvider.getFeederInfos((FeederNode) g.getNode("dl1")); assertEquals(ARROW_REACTIVE, feederInfos5.get(0).getComponentType()); assertEquals(ARROW_ACTIVE, feederInfos5.get(1).getComponentType()); diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/GraphMetadataTest.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/GraphMetadataTest.java index 3bd41ed7b..880804a42 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/GraphMetadataTest.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/GraphMetadataTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.svg; @@ -55,7 +56,7 @@ public void tearDown() throws Exception { @Test void test() throws IOException { - GraphMetadata metadata = new GraphMetadata(new LayoutParameters()); + GraphMetadata metadata = new GraphMetadata(new LayoutParameters(), new SvgParameters()); metadata.addComponent(new Component(BREAKER, ImmutableList.of(new AnchorPoint(5, 4, AnchorOrientation.NONE)), new ComponentSize(10, 12), "breaker", Collections.emptyMap(), null)); @@ -148,7 +149,7 @@ void test() throws IOException { @Test void testGraphMetadataWithLine() throws IOException { - GraphMetadata metadata = new GraphMetadata(new LayoutParameters()); + GraphMetadata metadata = new GraphMetadata(new LayoutParameters(), new SvgParameters()); metadata.addNodeMetadata(new GraphMetadata.NodeMetadata("STATION_EXAMPLE", "idSTATION_95_EXAMPLE", "vid1", null, LCC_CONVERTER_STATION, false, Direction.UNDEFINED, false, null, Collections.emptyList())); metadata.addNodeMetadata(new GraphMetadata.NodeMetadata(null, "bid1", "vid1", null, BUSBAR_SECTION, false, Direction.UNDEFINED, false, null, Collections.emptyList())); metadata.addNodeMetadata(new GraphMetadata.NodeMetadata(null, "lid1", "vid1", null, LINE, false, Direction.UNDEFINED, false, null, Collections.emptyList())); diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/SvgParametersTest.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/SvgParametersTest.java new file mode 100644 index 000000000..2f513cfe4 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/SvgParametersTest.java @@ -0,0 +1,76 @@ +/** + * 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.sld.svg; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author Sophie Frasnedo + */ +class SvgParametersTest { + + @Test + void test() { + SvgParameters svgParameters0 = new SvgParameters() + .setPrefixId("test") + .setUndefinedValueSymbol("\u002A") + .setLanguageTag("es") + .setVoltageValuePrecision(0) + .setPowerValuePrecision(3) + .setAngleValuePrecision(2) + .setCurrentValuePrecision(1) + .setBusInfoMargin(22) + .setFeederInfosIntraMargin(21) + .setFeederInfosOuterMargin(25) + .setFeederInfoSymmetry(true) + .setAddNodesInfos(true) + .setUseName(true) + .setAngleLabelShift(42) + .setLabelCentered(true) + .setLabelDiagonal(true) + .setTooltipEnabled(true) + .setSvgWidthAndHeightAdded(true) + .setCssLocation(SvgParameters.CssLocation.EXTERNAL_NO_IMPORT) + .setAvoidSVGComponentsDuplication(true) + .setDiagramName("diag") + .setDrawStraightWires(true) + .setShowGrid(true) + .setShowInternalNodes(true) + .setDisplayCurrentFeederInfo(true); + + SvgParameters svgParameters1 = new SvgParameters(svgParameters0); + + assertEquals(svgParameters0.getPrefixId(), svgParameters1.getPrefixId()); + assertEquals(svgParameters0.getUndefinedValueSymbol(), svgParameters1.getUndefinedValueSymbol()); + assertEquals(svgParameters0.getLanguageTag(), svgParameters1.getLanguageTag()); + assertEquals(svgParameters0.getVoltageValuePrecision(), svgParameters1.getVoltageValuePrecision()); + assertEquals(svgParameters0.getPowerValuePrecision(), svgParameters1.getPowerValuePrecision()); + assertEquals(svgParameters0.getAngleValuePrecision(), svgParameters1.getAngleValuePrecision()); + assertEquals(svgParameters0.getCurrentValuePrecision(), svgParameters1.getCurrentValuePrecision()); + assertEquals(svgParameters0.getBusInfoMargin(), svgParameters1.getBusInfoMargin(), 0); + assertEquals(svgParameters0.getFeederInfosIntraMargin(), svgParameters1.getFeederInfosIntraMargin(), 0); + assertEquals(svgParameters0.getFeederInfosOuterMargin(), svgParameters1.getFeederInfosOuterMargin(), 0); + assertEquals(svgParameters0.isFeederInfoSymmetry(), svgParameters1.isFeederInfoSymmetry()); + assertEquals(svgParameters0.isAddNodesInfos(), svgParameters1.isAddNodesInfos()); + assertEquals(svgParameters0.isUseName(), svgParameters1.isUseName()); + assertEquals(svgParameters0.getAngleLabelShift(), svgParameters1.getAngleLabelShift(), 0); + assertEquals(svgParameters0.isLabelCentered(), svgParameters1.isLabelCentered()); + assertEquals(svgParameters0.isLabelDiagonal(), svgParameters1.isLabelDiagonal()); + assertEquals(svgParameters0.isTooltipEnabled(), svgParameters1.isTooltipEnabled()); + assertEquals(svgParameters0.isSvgWidthAndHeightAdded(), svgParameters1.isSvgWidthAndHeightAdded()); + assertEquals(svgParameters0.getCssLocation(), svgParameters1.getCssLocation()); + assertEquals(svgParameters0.isAvoidSVGComponentsDuplication(), svgParameters1.isAvoidSVGComponentsDuplication()); + assertEquals(svgParameters0.getDiagramName(), svgParameters1.getDiagramName()); + assertEquals(svgParameters0.isDrawStraightWires(), svgParameters1.isDrawStraightWires()); + assertEquals(svgParameters0.isShowGrid(), svgParameters1.isShowGrid()); + assertEquals(svgParameters0.isShowInternalNodes(), svgParameters1.isShowInternalNodes()); + assertEquals(svgParameters0.isDisplayCurrentFeederInfo(), svgParameters1.isDisplayCurrentFeederInfo()); + } +} diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/NominalVoltageStyleTest.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/NominalVoltageStyleTest.java index 4bb82b0e4..42469cadf 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/NominalVoltageStyleTest.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/NominalVoltageStyleTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.util; @@ -16,7 +17,7 @@ import com.powsybl.sld.model.nodes.Edge; import com.powsybl.sld.model.nodes.FeederNode; import com.powsybl.sld.model.nodes.Node; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; +import com.powsybl.sld.svg.DefaultLabelProvider; import com.powsybl.sld.svg.FeederInfo; import com.powsybl.sld.svg.styles.NominalVoltageStyleProvider; import com.powsybl.sld.svg.styles.StyleClassConstants; @@ -95,9 +96,9 @@ public void setUp() { Networks.createSwitch(vl3, "b3WT_3", "b3WT_3", SwitchKind.BREAKER, true, true, true, 1, 2); } - private class NoFeederInfoProvider extends DefaultDiagramLabelProvider { + private class NoFeederInfoProvider extends DefaultLabelProvider { public NoFeederInfoProvider() { - super(NominalVoltageStyleTest.this.network, NominalVoltageStyleTest.this.componentLibrary, NominalVoltageStyleTest.this.layoutParameters); + super(NominalVoltageStyleTest.this.network, NominalVoltageStyleTest.this.componentLibrary, NominalVoltageStyleTest.this.layoutParameters, NominalVoltageStyleTest.this.svgParameters); } @Override @@ -154,21 +155,24 @@ void testAttributes() { void testSubstation() { SubstationGraph graph = graphBuilder.buildSubstationGraph(substation.getId()); substationGraphLayout(graph); - assertEquals(toString("/nominal_voltage_style_substation.svg"), toSVG(graph, "/nominal_voltage_style_substation.svg", new NoFeederInfoProvider(), styleProvider)); + + assertEquals(toString("/nominal_voltage_style_substation.svg"), toSVG(graph, "/nominal_voltage_style_substation.svg", componentLibrary, layoutParameters, svgParameters, new NoFeederInfoProvider(), styleProvider)); } @Test void testVl2() { VoltageLevelGraph graph2 = graphBuilder.buildVoltageLevelGraph(vl2.getId()); voltageLevelGraphLayout(graph2); - assertEquals(toString("/nominal_voltage_style_vl2.svg"), toSVG(graph2, "/nominal_voltage_style_vl2.svg", new NoFeederInfoProvider(), styleProvider)); + + assertEquals(toString("/nominal_voltage_style_vl2.svg"), toSVG(graph2, "/nominal_voltage_style_vl2.svg", componentLibrary, layoutParameters, svgParameters, new NoFeederInfoProvider(), styleProvider)); } @Test void testVl3() { VoltageLevelGraph graph3 = graphBuilder.buildVoltageLevelGraph(vl3.getId()); voltageLevelGraphLayout(graph3); - assertEquals(toString("/nominal_voltage_style_vl3.svg"), toSVG(graph3, "/nominal_voltage_style_vl3.svg", new NoFeederInfoProvider(), styleProvider)); + + assertEquals(toString("/nominal_voltage_style_vl3.svg"), toSVG(graph3, "/nominal_voltage_style_vl3.svg", componentLibrary, layoutParameters, svgParameters, new NoFeederInfoProvider(), styleProvider)); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/TopologicalStyleTest.java b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/TopologicalStyleTest.java index 141935a62..4726f497d 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/TopologicalStyleTest.java +++ b/single-line-diagram/single-line-diagram-core/src/test/java/com/powsybl/sld/util/TopologicalStyleTest.java @@ -3,6 +3,7 @@ * 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/. + * SPDX-License-Identifier: MPL-2.0 */ package com.powsybl.sld.util; @@ -140,6 +141,7 @@ void test() throws IOException { void testSubstation() { SubstationGraph graph = graphBuilder.buildSubstationGraph(substation.getId()); substationGraphLayout(graph); - assertEquals(toString("/topological_style_substation.svg"), toSVG(graph, "/topological_style_substation.svg")); + + assertEquals(toString("/topological_style_substation.svg"), toSVG(graph, "/topological_style_substation.svg", componentLibrary, layoutParameters, svgParameters, getDefaultDiagramLabelProvider(), getDefaultDiagramStyleProvider())); } } diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json b/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json index 52dcf46cd..633669e93 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json @@ -536,58 +536,63 @@ "electricalNodeInfos" : [ ], "busInfos" : [ ], "layoutParams" : { - "voltageLevelPadding" : { - "left" : 20.0, - "top" : 60.0, - "right" : 20.0, - "bottom" : 60.0 - }, - "diagramPadding" : { - "left" : 20.0, - "top" : 20.0, - "right" : 20.0, - "bottom" : 20.0 - }, "verticalSpaceBus" : 25.0, "horizontalBusPadding" : 20.0, "cellWidth" : 50.0, "externCellHeight" : 250.0, "internCellHeight" : 40.0, "stackHeight" : 30.0, - "showGrid" : false, - "tooltipEnabled" : false, - "showInternalNodes" : false, - "scaleFactor" : 1.0, - "drawStraightWires" : false, "horizontalSnakeLinePadding" : 20.0, "verticalSnakeLinePadding" : 25.0, - "feederInfosOuterMargin" : 20.0, "spaceForFeederInfos" : 50.0, - "diagramName" : null, - "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : true, "maxComponentHeight" : 12.0, "minSpaceBetweenComponents" : 15.0, "minExternCellHeight" : 80.0, - "labelCentered" : false, - "labelDiagonal" : false, - "angleLabelShift" : 15.0, - "addNodesInfos" : false, - "feederInfoSymmetry" : false, - "cssLocation" : "INSERTED_IN_SVG", - "svgWidthAndHeightAdded" : false, - "useName" : false, - "feederInfosIntraMargin" : 10.0, - "busInfoMargin" : 0.0, + "voltageLevelPadding" : { + "left" : 20.0, + "top" : 60.0, + "right" : 20.0, + "bottom" : 60.0 + }, + "diagramPadding" : { + "left" : 20.0, + "top" : 20.0, + "right" : 20.0, + "bottom" : 20.0 + }, "busbarsAlignment" : "FIRST", "componentsOnBusbars" : [ "DISCONNECTOR" ], + "removeFictitiousSwitchNodes" : false, + "cgmesScaleFactor" : 1.0, + "cgmesDiagramName" : null, + "cgmesUseNames" : true + }, + "svgParams" : { + "prefixId" : "", + "undefinedValueSymbol" : "—", "languageTag" : "en", "voltageValuePrecision" : 1, "powerValuePrecision" : 0, "angleValuePrecision" : 1, "currentValuePrecision" : 0, - "displayCurrentFeederInfo" : false, - "undefinedValueSymbol" : "—", - "removeFictitiousSwitchNodes" : false + "busInfoMargin" : 0.0, + "feederInfosIntraMargin" : 10.0, + "feederInfosOuterMargin" : 20.0, + "feederInfoSymmetry" : false, + "addNodesInfos" : false, + "useName" : false, + "angleLabelShift" : 15.0, + "labelCentered" : false, + "labelDiagonal" : false, + "tooltipEnabled" : false, + "svgWidthAndHeightAdded" : false, + "cssLocation" : "INSERTED_IN_SVG", + "avoidSVGComponentsDuplication" : false, + "diagramName" : null, + "drawStraightWires" : false, + "showGrid" : false, + "showInternalNodes" : false, + "displayCurrentFeederInfo" : false } } \ No newline at end of file diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json b/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json index ceb9bdbc1..538754e51 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json @@ -295,58 +295,63 @@ "electricalNodeInfos" : [ ], "busInfos" : [ ], "layoutParams" : { - "voltageLevelPadding" : { - "left" : 20.0, - "top" : 60.0, - "right" : 20.0, - "bottom" : 60.0 - }, - "diagramPadding" : { - "left" : 20.0, - "top" : 20.0, - "right" : 20.0, - "bottom" : 20.0 - }, "verticalSpaceBus" : 25.0, "horizontalBusPadding" : 20.0, "cellWidth" : 50.0, "externCellHeight" : 250.0, "internCellHeight" : 40.0, "stackHeight" : 30.0, - "showGrid" : false, - "tooltipEnabled" : false, - "showInternalNodes" : false, - "scaleFactor" : 1.0, - "drawStraightWires" : false, "horizontalSnakeLinePadding" : 20.0, "verticalSnakeLinePadding" : 25.0, - "feederInfosOuterMargin" : 20.0, "spaceForFeederInfos" : 50.0, - "diagramName" : null, - "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : true, "maxComponentHeight" : 12.0, "minSpaceBetweenComponents" : 15.0, "minExternCellHeight" : 80.0, - "labelCentered" : false, - "labelDiagonal" : false, - "angleLabelShift" : 15.0, - "addNodesInfos" : false, - "feederInfoSymmetry" : false, - "cssLocation" : "INSERTED_IN_SVG", - "svgWidthAndHeightAdded" : false, - "useName" : false, - "feederInfosIntraMargin" : 10.0, - "busInfoMargin" : 0.0, + "voltageLevelPadding" : { + "left" : 20.0, + "top" : 60.0, + "right" : 20.0, + "bottom" : 60.0 + }, + "diagramPadding" : { + "left" : 20.0, + "top" : 20.0, + "right" : 20.0, + "bottom" : 20.0 + }, "busbarsAlignment" : "FIRST", "componentsOnBusbars" : [ "DISCONNECTOR" ], + "removeFictitiousSwitchNodes" : false, + "cgmesScaleFactor" : 1.0, + "cgmesDiagramName" : null, + "cgmesUseNames" : true + }, + "svgParams" : { + "prefixId" : "", + "undefinedValueSymbol" : "—", "languageTag" : "en", "voltageValuePrecision" : 1, "powerValuePrecision" : 0, "angleValuePrecision" : 1, "currentValuePrecision" : 0, - "displayCurrentFeederInfo" : false, - "undefinedValueSymbol" : "—", - "removeFictitiousSwitchNodes" : false + "busInfoMargin" : 0.0, + "feederInfosIntraMargin" : 10.0, + "feederInfosOuterMargin" : 20.0, + "feederInfoSymmetry" : false, + "addNodesInfos" : false, + "useName" : false, + "angleLabelShift" : 15.0, + "labelCentered" : false, + "labelDiagonal" : false, + "tooltipEnabled" : false, + "svgWidthAndHeightAdded" : false, + "cssLocation" : "INSERTED_IN_SVG", + "avoidSVGComponentsDuplication" : false, + "diagramName" : null, + "drawStraightWires" : false, + "showGrid" : false, + "showInternalNodes" : false, + "displayCurrentFeederInfo" : false } } \ No newline at end of file diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_metadata.json b/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_metadata.json index 17bb03834..b69da3450 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_metadata.json +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_metadata.json @@ -2918,58 +2918,63 @@ "electricalNodeInfos" : [ ], "busInfos" : [ ], "layoutParams" : { - "voltageLevelPadding" : { - "left" : 20.0, - "top" : 60.0, - "right" : 20.0, - "bottom" : 60.0 - }, - "diagramPadding" : { - "left" : 20.0, - "top" : 20.0, - "right" : 20.0, - "bottom" : 20.0 - }, "verticalSpaceBus" : 25.0, "horizontalBusPadding" : 20.0, "cellWidth" : 50.0, "externCellHeight" : 250.0, "internCellHeight" : 40.0, "stackHeight" : 30.0, - "showGrid" : false, - "tooltipEnabled" : false, - "showInternalNodes" : false, - "scaleFactor" : 1.0, - "drawStraightWires" : false, "horizontalSnakeLinePadding" : 30.0, "verticalSnakeLinePadding" : 30.0, - "feederInfosOuterMargin" : 20.0, "spaceForFeederInfos" : 50.0, - "diagramName" : null, - "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : true, "maxComponentHeight" : 12.0, "minSpaceBetweenComponents" : 15.0, "minExternCellHeight" : 80.0, - "labelCentered" : false, - "labelDiagonal" : false, - "angleLabelShift" : 15.0, - "addNodesInfos" : false, - "feederInfoSymmetry" : false, - "cssLocation" : "INSERTED_IN_SVG", - "svgWidthAndHeightAdded" : true, - "useName" : true, - "feederInfosIntraMargin" : 10.0, - "busInfoMargin" : 0.0, + "voltageLevelPadding" : { + "left" : 20.0, + "top" : 60.0, + "right" : 20.0, + "bottom" : 60.0 + }, + "diagramPadding" : { + "left" : 20.0, + "top" : 20.0, + "right" : 20.0, + "bottom" : 20.0 + }, "busbarsAlignment" : "FIRST", "componentsOnBusbars" : [ "DISCONNECTOR" ], + "removeFictitiousSwitchNodes" : false, + "cgmesScaleFactor" : 1.0, + "cgmesDiagramName" : null, + "cgmesUseNames" : true + }, + "svgParams" : { + "prefixId" : "", + "undefinedValueSymbol" : "—", "languageTag" : "en", "voltageValuePrecision" : 1, "powerValuePrecision" : 0, "angleValuePrecision" : 1, "currentValuePrecision" : 0, - "displayCurrentFeederInfo" : false, - "undefinedValueSymbol" : "—", - "removeFictitiousSwitchNodes" : false + "busInfoMargin" : 0.0, + "feederInfosIntraMargin" : 10.0, + "feederInfosOuterMargin" : 20.0, + "feederInfoSymmetry" : false, + "addNodesInfos" : false, + "useName" : true, + "angleLabelShift" : 15.0, + "labelCentered" : false, + "labelDiagonal" : false, + "tooltipEnabled" : false, + "svgWidthAndHeightAdded" : true, + "cssLocation" : "INSERTED_IN_SVG", + "avoidSVGComponentsDuplication" : false, + "diagramName" : null, + "drawStraightWires" : false, + "showGrid" : false, + "showInternalNodes" : false, + "displayCurrentFeederInfo" : false } } \ No newline at end of file diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json b/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json index aacd34a21..77416952c 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/substDiag_with_hvdc_line_metadata.json @@ -266,58 +266,63 @@ "electricalNodeInfos" : [ ], "busInfos" : [ ], "layoutParams" : { - "voltageLevelPadding" : { - "left" : 20.0, - "top" : 60.0, - "right" : 20.0, - "bottom" : 60.0 - }, - "diagramPadding" : { - "left" : 20.0, - "top" : 20.0, - "right" : 20.0, - "bottom" : 20.0 - }, "verticalSpaceBus" : 25.0, "horizontalBusPadding" : 20.0, "cellWidth" : 50.0, "externCellHeight" : 250.0, "internCellHeight" : 40.0, "stackHeight" : 30.0, - "showGrid" : false, - "tooltipEnabled" : false, - "showInternalNodes" : false, - "scaleFactor" : 1.0, - "drawStraightWires" : false, "horizontalSnakeLinePadding" : 30.0, "verticalSnakeLinePadding" : 30.0, - "feederInfosOuterMargin" : 20.0, "spaceForFeederInfos" : 50.0, - "diagramName" : null, - "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : true, "maxComponentHeight" : 12.0, "minSpaceBetweenComponents" : 15.0, "minExternCellHeight" : 80.0, - "labelCentered" : false, - "labelDiagonal" : false, - "angleLabelShift" : 15.0, - "addNodesInfos" : false, - "feederInfoSymmetry" : false, - "cssLocation" : "INSERTED_IN_SVG", - "svgWidthAndHeightAdded" : true, - "useName" : true, - "feederInfosIntraMargin" : 10.0, - "busInfoMargin" : 0.0, + "voltageLevelPadding" : { + "left" : 20.0, + "top" : 60.0, + "right" : 20.0, + "bottom" : 60.0 + }, + "diagramPadding" : { + "left" : 20.0, + "top" : 20.0, + "right" : 20.0, + "bottom" : 20.0 + }, "busbarsAlignment" : "FIRST", "componentsOnBusbars" : [ "DISCONNECTOR" ], + "removeFictitiousSwitchNodes" : false, + "cgmesScaleFactor" : 1.0, + "cgmesDiagramName" : null, + "cgmesUseNames" : true + }, + "svgParams" : { + "prefixId" : "", + "undefinedValueSymbol" : "—", "languageTag" : "en", "voltageValuePrecision" : 1, "powerValuePrecision" : 0, "angleValuePrecision" : 1, "currentValuePrecision" : 0, - "displayCurrentFeederInfo" : false, - "undefinedValueSymbol" : "—", - "removeFictitiousSwitchNodes" : false + "busInfoMargin" : 0.0, + "feederInfosIntraMargin" : 10.0, + "feederInfosOuterMargin" : 20.0, + "feederInfoSymmetry" : false, + "addNodesInfos" : false, + "useName" : true, + "angleLabelShift" : 15.0, + "labelCentered" : false, + "labelDiagonal" : false, + "tooltipEnabled" : false, + "svgWidthAndHeightAdded" : true, + "cssLocation" : "INSERTED_IN_SVG", + "avoidSVGComponentsDuplication" : false, + "diagramName" : null, + "drawStraightWires" : false, + "showGrid" : false, + "showInternalNodes" : false, + "displayCurrentFeederInfo" : false } } \ No newline at end of file diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/vlDiag_metadata.json b/single-line-diagram/single-line-diagram-core/src/test/resources/vlDiag_metadata.json index 9afb3d18a..4f71f0323 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/vlDiag_metadata.json +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/vlDiag_metadata.json @@ -1451,58 +1451,63 @@ } ], "busInfos" : [ ], "layoutParams" : { - "voltageLevelPadding" : { - "left" : 20.0, - "top" : 60.0, - "right" : 20.0, - "bottom" : 60.0 - }, - "diagramPadding" : { - "left" : 20.0, - "top" : 20.0, - "right" : 20.0, - "bottom" : 20.0 - }, "verticalSpaceBus" : 25.0, "horizontalBusPadding" : 20.0, "cellWidth" : 80.0, "externCellHeight" : 250.0, "internCellHeight" : 40.0, "stackHeight" : 30.0, - "showGrid" : false, - "tooltipEnabled" : false, - "showInternalNodes" : false, - "scaleFactor" : 1.0, - "drawStraightWires" : false, "horizontalSnakeLinePadding" : 30.0, "verticalSnakeLinePadding" : 30.0, - "feederInfosOuterMargin" : 20.0, "spaceForFeederInfos" : 50.0, - "diagramName" : null, - "avoidSVGComponentsDuplication" : true, "adaptCellHeightToContent" : true, "maxComponentHeight" : 12.0, "minSpaceBetweenComponents" : 15.0, "minExternCellHeight" : 80.0, - "labelCentered" : false, - "labelDiagonal" : false, - "angleLabelShift" : 15.0, - "addNodesInfos" : true, - "feederInfoSymmetry" : false, - "cssLocation" : "INSERTED_IN_SVG", - "svgWidthAndHeightAdded" : true, - "useName" : true, - "feederInfosIntraMargin" : 10.0, - "busInfoMargin" : 0.0, + "voltageLevelPadding" : { + "left" : 20.0, + "top" : 60.0, + "right" : 20.0, + "bottom" : 60.0 + }, + "diagramPadding" : { + "left" : 20.0, + "top" : 20.0, + "right" : 20.0, + "bottom" : 20.0 + }, "busbarsAlignment" : "FIRST", "componentsOnBusbars" : [ "DISCONNECTOR" ], + "removeFictitiousSwitchNodes" : false, + "cgmesScaleFactor" : 1.0, + "cgmesDiagramName" : null, + "cgmesUseNames" : true + }, + "svgParams" : { + "prefixId" : "", + "undefinedValueSymbol" : "—", "languageTag" : "en", "voltageValuePrecision" : 1, "powerValuePrecision" : 0, "angleValuePrecision" : 1, "currentValuePrecision" : 0, - "displayCurrentFeederInfo" : false, - "undefinedValueSymbol" : "—", - "removeFictitiousSwitchNodes" : false + "busInfoMargin" : 0.0, + "feederInfosIntraMargin" : 10.0, + "feederInfosOuterMargin" : 20.0, + "feederInfoSymmetry" : false, + "addNodesInfos" : true, + "useName" : true, + "angleLabelShift" : 15.0, + "labelCentered" : false, + "labelDiagonal" : false, + "tooltipEnabled" : false, + "svgWidthAndHeightAdded" : true, + "cssLocation" : "INSERTED_IN_SVG", + "avoidSVGComponentsDuplication" : true, + "diagramName" : null, + "drawStraightWires" : false, + "showGrid" : false, + "showInternalNodes" : false, + "displayCurrentFeederInfo" : false } } \ No newline at end of file