From 64187fb71a33d09e1df5b2f1189c5d590139ce18 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Fri, 3 Dec 2021 12:22:44 +0100 Subject: [PATCH 1/7] Add test with 5 feeder info Signed-off-by: Thomas ADAM --- .../com/powsybl/sld/iidm/TestSVGWriter.java | 34 +++ .../test/resources/vl1_many_feeder_values.svg | 268 ++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java index ea5245be1..ff388a7a4 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java @@ -50,6 +50,8 @@ public class TestSVGWriter extends AbstractTestCaseIidm { private SubstationGraph substG; private DiagramLabelProvider initValueProvider; private DiagramLabelProvider noFeederInfoProvider; + private DiagramLabelProvider manyFeederInfoProvider; + private ZoneGraph zGraph; private void createVoltageLevelGraphs() { @@ -688,6 +690,31 @@ public List getNodeDecorators(Node node) { return new ArrayList<>(); } }; + + // many feeder values provider example for the test : + // + manyFeederInfoProvider = new DefaultDiagramLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters) { + + @Override + public List getFeederInfos(FeederNode node) { + List feederInfos = Arrays.asList( + new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "10", null), + new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "20", null), + new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "30", null), + new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "40", null), + new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "50", null)); + boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederArrowSymmetry(); + if (!feederArrowSymmetry) { + Collections.reverse(feederInfos); + } + return feederInfos; + } + + @Override + public List getNodeDecorators(Node node) { + return new ArrayList<>(); + } + }; } @Test @@ -744,6 +771,13 @@ public void testSubstationNoFeederInfos() { toSVG(substG, "/substation_no_feeder_values.svg", noFeederInfoProvider, new BasicStyleProvider())); } + @Test + public void testSubstationManyFeederInfos() { + // SVG file generation for substation and comparison to reference but with many feeder values + assertEquals(toString("/vl1_many_feeder_values.svg"), + toSVG(g1, "/vl1_many_feeder_values.svg", manyFeederInfoProvider, new BasicStyleProvider())); + } + @Test public void testVl1Optimized() { // Same tests than before, with optimized svg diff --git a/single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg b/single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg new file mode 100644 index 000000000..423e75018 --- /dev/null +++ b/single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg @@ -0,0 +1,268 @@ + + + + + + + + vl1_bbs1 + + + + vl1_bbs2 + + + + + + + + + + + + + + + + + + + + 10 + + + + + 20 + + + + + 30 + + + + + 40 + + + + + 50 + + + + + + + + + + + + + + 50 + + + + + 40 + + + + + 30 + + + + + 20 + + + + + 10 + + + + + + + + + + + + + + 10 + + + + + 20 + + + + + 30 + + + + + 40 + + + + + 50 + + + + + + + + 10 + + + + + 20 + + + + + 30 + + + + + 40 + + + + + 50 + + + + + + + + + + + + + + + + + + + + + + + + + + + vl1_load1 + + + + + + + + + + + + + vl1_trf1 + + + + + + + + + + + vl1_trf2 + + + vl1_trf2 + + + + + + + + + + + + + + + + From de0fa13bcddea1f08dad489b4d6f15c7b3d2b441 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Tue, 25 Jan 2022 09:06:53 +0100 Subject: [PATCH 2/7] Add new test with up to N Feeder Infos Signed-off-by: Thomas ADAM --- .../sld/iidm/TestCase14UpToNFeederInfos.java | 102 ++++++++++++++ .../com/powsybl/sld/iidm/TestSVGWriter.java | 2 + .../resources/TestCase14UpToNFeederInfos.svg | 131 ++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java create mode 100644 single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java new file mode 100644 index 000000000..54c5b3852 --- /dev/null +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java @@ -0,0 +1,102 @@ +/** + * 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.iidm; + +import com.powsybl.iidm.network.Country; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.SwitchKind; +import com.powsybl.iidm.network.TopologyKind; +import com.powsybl.sld.NetworkGraphBuilder; +import com.powsybl.sld.iidm.extensions.ConnectablePosition; +import com.powsybl.sld.model.BusCell; +import com.powsybl.sld.model.FeederNode; +import com.powsybl.sld.model.Node; +import com.powsybl.sld.model.VoltageLevelGraph; +import com.powsybl.sld.svg.BasicStyleProvider; +import com.powsybl.sld.svg.DefaultDiagramLabelProvider; +import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.svg.FeederInfo; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static com.powsybl.sld.library.ComponentTypeName.ARROW_ACTIVE; +import static com.powsybl.sld.library.ComponentTypeName.ARROW_REACTIVE; +import static org.junit.Assert.assertEquals; + +/** + *
+ * l
+ * |
+ * b
+ * |
+ * d
+ * |
+ * ------ bbs
+ * 
+ * + * @author Thomas Adam + */ +public class TestCase14UpToNFeederInfos extends AbstractTestCaseIidm { + + private DiagramLabelProvider manyFeederInfoProvider; + + @Before + public void setUp() { + network = Network.create("testCase14", "test"); + graphBuilder = new NetworkGraphBuilder(network); + substation = createSubstation(network, "s", "s", Country.FR); + vl = createVoltageLevel(substation, "vl", "vl", TopologyKind.NODE_BREAKER, 380, 10); + createBusBarSection(vl, "bbs", "bbs", 0, 1, 1); + createLoad(vl, "l", "l", "l", 0, ConnectablePosition.Direction.TOP, 2, 10, 10); + createSwitch(vl, "d", "d", SwitchKind.DISCONNECTOR, false, false, false, 0, 1); + createSwitch(vl, "b", "b", SwitchKind.BREAKER, false, false, false, 1, 2); + + // many feeder values provider example for the test : + // + manyFeederInfoProvider = new DefaultDiagramLabelProvider(network, componentLibrary, layoutParameters) { + + @Override + public List getFeederInfos(FeederNode node) { + List feederInfos = Arrays.asList( + new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "10", null), + new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "20", null), + new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "30", null), + new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "40", null), + new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "50", null)); + boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederArrowSymmetry(); + if (!feederArrowSymmetry) { + Collections.reverse(feederInfos); + } + return feederInfos; + } + + @Override + public List getNodeDecorators(Node node) { + return new ArrayList<>(); + } + }; + } + + @Test + public void test() { + // build graph + VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId(), true); + + layoutParameters.setMinSpaceForFeederArrows(120); + + // Run layout + voltageLevelGraphLayout(g); + + // write SVG and compare to reference + assertEquals(toString("/TestCase14UpToNFeederInfos.svg"), toSVG(g, "/TestCase14UpToNFeederInfos.svg", manyFeederInfoProvider, new BasicStyleProvider())); + } +} diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java index ff388a7a4..6e5bb056d 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java @@ -773,6 +773,8 @@ public void testSubstationNoFeederInfos() { @Test public void testSubstationManyFeederInfos() { + // FIXME : change MinSpaceForFeederArrows seems to have no impact + layoutParameters.setMinSpaceForFeederArrows(120); // SVG file generation for substation and comparison to reference but with many feeder values assertEquals(toString("/vl1_many_feeder_values.svg"), toSVG(g1, "/vl1_many_feeder_values.svg", manyFeederInfoProvider, new BasicStyleProvider())); diff --git a/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg new file mode 100644 index 000000000..f66d49219 --- /dev/null +++ b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + bbs + + + + + + + + + + + + + l + + + + + + + + + + + + + + + + + + + + 10 + + + + + 20 + + + + + 30 + + + + + 40 + + + + + 50 + + + + + + + + + + + + From e020eeb56d7c9084295379d30833797abeaf2076 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Tue, 25 Jan 2022 10:01:42 +0100 Subject: [PATCH 3/7] Rename Arrow to FeederInfo into DefaultSVGWriter Signed-off-by: Thomas ADAM --- .../com/powsybl/sld/svg/DefaultSVGWriter.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java index 0cc902ea2..67c5b06c1 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java @@ -617,17 +617,17 @@ protected void insertComponentSVGIntoDocumentSVG(String prefixId, insertSVGIntoDocumentSVG(node.getName(), componentType, g, elementAttributesSetter); } - protected void insertArrowSVGIntoDocumentSVG(String arrowType, String prefixId, Element g, double angle) { + protected void insertFeederInfoSVGIntoDocumentSVG(String feederInfoType, String prefixId, Element g, double angle) { BiConsumer elementAttributesSetter - = (e, subComponent) -> setArrowAttributes(arrowType, prefixId, g, e, subComponent, angle); - insertSVGIntoDocumentSVG("", arrowType, g, elementAttributesSetter); + = (e, subComponent) -> setFeederInfoAttributes(feederInfoType, prefixId, g, e, subComponent, angle); + insertSVGIntoDocumentSVG("", feederInfoType, g, elementAttributesSetter); } - private void setArrowAttributes(String arrowType, String prefixId, Element g, Element e, String subComponent, double angle) { + private void setFeederInfoAttributes(String feederInfoType, String prefixId, Element g, Element e, String subComponent, double angle) { replaceId(g, e, prefixId); - componentLibrary.getSubComponentStyleClass(arrowType, subComponent).ifPresent(style -> e.setAttribute(CLASS, style)); + componentLibrary.getSubComponentStyleClass(feederInfoType, subComponent).ifPresent(style -> e.setAttribute(CLASS, style)); if (Math.abs(angle) > 0) { - ComponentSize componentSize = componentLibrary.getSize(arrowType); + ComponentSize componentSize = componentLibrary.getSize(feederInfoType); double cx = componentSize.getWidth() / 2; double cy = componentSize.getHeight() / 2; e.setAttribute(TRANSFORM, ROTATE + "(" + angle + "," + cx + "," + cy + ")"); @@ -761,13 +761,13 @@ private double[] getNodeTranslate(Node node) { return new double[]{translateX, translateY}; } - protected void transformArrow(List points, ComponentSize componentSize, double shift, Element g) { + protected void transformFeederInfo(List points, ComponentSize componentSize, double shift, Element g) { Point pointA = points.get(0); Point pointB = points.get(1); double distancePoints = pointA.distance(pointB); // Case of wires with non-direct straight lines: if wire distance between first 2 points is too small to display - // the arrow, checks if the distance between the 2nd and the 3rd points is big enough + // the feeder info, checks if the distance between the 2nd and the 3rd points is big enough if (points.size() > 2 && distancePoints < 3 * componentSize.getHeight()) { double distancePoints23 = points.get(1).distance(points.get(2)); if (distancePoints23 > 3 * componentSize.getHeight()) { @@ -785,20 +785,20 @@ protected void transformArrow(List points, ComponentSize componentSize, d double cosAngle = dx / distancePoints; double sinAngle = dy / distancePoints; - // If not enough space to have layoutParameters.getArrowDistance() at both sides of the 2 arrows, - // we compute the distance between feeder anchor and first arrow so that the two arrows are centered. - double distFeederAnchorToFirstArrowCenter = + // If not enough space to have layoutParameters.getArrowDistance() at both sides of the 2 feeder infos, + // we compute the distance between feeder anchor and first feeder info so that the two feeder infos are centered. + double distFeederAnchorToFirstFeederInfoCenter = distancePoints >= 2 * layoutParameters.getArrowDistance() + 2 * componentSize.getHeight() ? layoutParameters.getArrowDistance() : (distancePoints - 2 * componentSize.getHeight()) / 2; - double x = pointA.getX() + cosAngle * (distFeederAnchorToFirstArrowCenter + shift); - double y = pointA.getY() + sinAngle * (distFeederAnchorToFirstArrowCenter + shift); + double x = pointA.getX() + cosAngle * (distFeederAnchorToFirstFeederInfoCenter + shift); + double y = pointA.getY() + sinAngle * (distFeederAnchorToFirstFeederInfoCenter + shift); - double arrowRotationAngle = Math.atan(dy / dx) - Math.PI / 2; - if (arrowRotationAngle < -Math.PI / 2) { - arrowRotationAngle += Math.PI; + double feederInfoRotationAngle = Math.atan(dy / dx) - Math.PI / 2; + if (feederInfoRotationAngle < -Math.PI / 2) { + feederInfoRotationAngle += Math.PI; } - g.setAttribute(TRANSFORM, getTransformString(x, y, arrowRotationAngle, componentSize)); + g.setAttribute(TRANSFORM, getTransformString(x, y, feederInfoRotationAngle, componentSize)); } } @@ -851,13 +851,13 @@ protected void insertFeederInfos(String prefixId, points.add(new Point(feederNode.getDiagramCoordinates())); } - int iArrow = 0; + int iFeederInfo = 0; for (FeederInfo feederInfo : initProvider.getFeederInfos(feederNode)) { - // Compute shifting even if not displayed to ensure aligned arrows + // Compute shifting even if not displayed to ensure aligned feeder info double height = componentLibrary.getSize(feederInfo.getComponentType()).getHeight(); - double shiftArrow = iArrow++ * 2 * height; + double shiftFeederInfo = iFeederInfo++ * 2 * height; if (!feederInfo.isEmpty()) { - drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftArrow, metadata); + drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftFeederInfo, metadata); addFeederInfoComponentMetadata(metadata, feederInfo.getComponentType()); } } @@ -886,17 +886,17 @@ private void drawFeederInfo(String prefixId, String feederNodeId, List po List styles = new ArrayList<>(3); componentLibrary.getComponentStyleClass(feederInfo.getComponentType()).ifPresent(styles::add); - transformArrow(points, size, shift, g); + transformFeederInfo(points, size, shift, g); String svgId = escapeId(feederNodeId) + "_" + feederInfo.getComponentType(); g.setAttribute("id", svgId); metadata.addFeederInfoMetadata(new FeederInfoMetadata(svgId, feederNodeId, feederInfo.getUserDefinedId())); - // we draw the arrow only if direction is present + // we draw the feeder info only if direction is present feederInfo.getDirection().ifPresent(direction -> { double rotationAngle = points.get(0).getY() > points.get(1).getY() ? 180 : 0; - insertArrowSVGIntoDocumentSVG(feederInfo.getComponentType(), prefixId, g, rotationAngle); + insertFeederInfoSVGIntoDocumentSVG(feederInfo.getComponentType(), prefixId, g, rotationAngle); styles.add(direction == Direction.OUT ? OUT_CLASS : IN_CLASS); }); From a35924392ce351e3a3a5411691e86b9e4af72d70 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Tue, 25 Jan 2022 14:12:58 +0100 Subject: [PATCH 4/7] Remove unit test into TestSVGWriter Signed-off-by: Thomas ADAM --- .../com/powsybl/sld/iidm/TestSVGWriter.java | 36 --- .../test/resources/vl1_many_feeder_values.svg | 268 ------------------ 2 files changed, 304 deletions(-) delete mode 100644 single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java index 6e5bb056d..ea5245be1 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java @@ -50,8 +50,6 @@ public class TestSVGWriter extends AbstractTestCaseIidm { private SubstationGraph substG; private DiagramLabelProvider initValueProvider; private DiagramLabelProvider noFeederInfoProvider; - private DiagramLabelProvider manyFeederInfoProvider; - private ZoneGraph zGraph; private void createVoltageLevelGraphs() { @@ -690,31 +688,6 @@ public List getNodeDecorators(Node node) { return new ArrayList<>(); } }; - - // many feeder values provider example for the test : - // - manyFeederInfoProvider = new DefaultDiagramLabelProvider(Network.create("empty", ""), componentLibrary, layoutParameters) { - - @Override - public List getFeederInfos(FeederNode node) { - List feederInfos = Arrays.asList( - new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "10", null), - new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "20", null), - new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "30", null), - new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "40", null), - new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "50", null)); - boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederArrowSymmetry(); - if (!feederArrowSymmetry) { - Collections.reverse(feederInfos); - } - return feederInfos; - } - - @Override - public List getNodeDecorators(Node node) { - return new ArrayList<>(); - } - }; } @Test @@ -771,15 +744,6 @@ public void testSubstationNoFeederInfos() { toSVG(substG, "/substation_no_feeder_values.svg", noFeederInfoProvider, new BasicStyleProvider())); } - @Test - public void testSubstationManyFeederInfos() { - // FIXME : change MinSpaceForFeederArrows seems to have no impact - layoutParameters.setMinSpaceForFeederArrows(120); - // SVG file generation for substation and comparison to reference but with many feeder values - assertEquals(toString("/vl1_many_feeder_values.svg"), - toSVG(g1, "/vl1_many_feeder_values.svg", manyFeederInfoProvider, new BasicStyleProvider())); - } - @Test public void testVl1Optimized() { // Same tests than before, with optimized svg diff --git a/single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg b/single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg deleted file mode 100644 index 423e75018..000000000 --- a/single-line-diagram-core/src/test/resources/vl1_many_feeder_values.svg +++ /dev/null @@ -1,268 +0,0 @@ - - - - - - - - vl1_bbs1 - - - - vl1_bbs2 - - - - - - - - - - - - - - - - - - - - 10 - - - - - 20 - - - - - 30 - - - - - 40 - - - - - 50 - - - - - - - - - - - - - - 50 - - - - - 40 - - - - - 30 - - - - - 20 - - - - - 10 - - - - - - - - - - - - - - 10 - - - - - 20 - - - - - 30 - - - - - 40 - - - - - 50 - - - - - - - - 10 - - - - - 20 - - - - - 30 - - - - - 40 - - - - - 50 - - - - - - - - - - - - - - - - - - - - - - - - - - - vl1_load1 - - - - - - - - - - - - - vl1_trf1 - - - - - - - - - - - vl1_trf2 - - - vl1_trf2 - - - - - - - - - - - - - - - - From a501039df8ba09f05dae2ace34a6a3c92302d359 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Tue, 25 Jan 2022 15:14:47 +0100 Subject: [PATCH 5/7] Rename Arrow to FeederInfo into LayoutParameters & adding feederInfosIntraMargin parameter Signed-off-by: Thomas ADAM --- .../powsybl/sld/layout/LayoutParameters.java | 64 +++++++++++-------- .../layout/PositionVoltageLevelLayout.java | 2 +- .../sld/svg/DefaultDiagramLabelProvider.java | 2 +- .../com/powsybl/sld/svg/DefaultSVGWriter.java | 4 +- .../sld/iidm/TestCase14UpToNFeederInfos.java | 4 +- .../com/powsybl/sld/iidm/TestSVGWriter.java | 4 +- .../sld/layout/LayoutParametersTest.java | 19 ++++-- .../sld/svg/FeederInfoProviderTest.java | 6 +- .../TestSldClassSubstationMetadata.json | 9 +-- .../resources/TestSldClassVlMetadata.json | 9 +-- .../test/resources/substDiag_metadata.json | 9 +-- ...stDiag_metadata_nominal_voltage_style.json | 10 +-- .../src/test/resources/vlDiag_metadata.json | 9 +-- 13 files changed, 88 insertions(+), 63 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java index 60630d9b3..a46c5d53e 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java @@ -45,8 +45,8 @@ public class LayoutParameters { private double horizontalSnakeLinePadding = 20; private double verticalSnakeLinePadding = 25; - private double arrowDistance = 20; - private double minSpaceForFeederArrows = 50; + private double feederInfosOuterMargin = 20; + private double spaceForFeederInfos = 50; private boolean avoidSVGComponentsDuplication = false; @@ -64,7 +64,7 @@ public class LayoutParameters { private boolean addNodesInfos = false; - private boolean feederArrowSymmetry = false; + private boolean feederInfoSymmetry = false; private CssLocation cssLocation = CssLocation.INSERTED_IN_SVG; @@ -76,6 +76,8 @@ public class LayoutParameters { private boolean useName = false; + private double feederInfosIntraMargin = 20; + @JsonIgnore private Map componentsSize; @@ -99,8 +101,8 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve @JsonProperty("drawStraightWires") boolean drawStraightWires, @JsonProperty("horizontalSnakeLinePadding") double horizontalSnakeLinePadding, @JsonProperty("verticalSnakeLinePadding") double verticalSnakeLinePadding, - @JsonProperty("arrowDistance") double arrowDistance, - @JsonProperty("minSpaceForFeederArrows") double minSpaceForFeederArrows, + @JsonProperty("feederInfosOuterMargin") double feederInfosOuterMargin, + @JsonProperty("spaceForFeederInfos") double spaceForFeederInfos, @JsonProperty("diagramName") String diagramName, @JsonProperty("avoidSVGComponentsDuplication") boolean avoidSVGComponentsDuplication, @JsonProperty("adaptCellHeightToContent") boolean adaptCellHeightToContent, @@ -112,10 +114,11 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve @JsonProperty("angleLabelShift") double angleLabelShift, @JsonProperty("highlightLineState") boolean highlightLineState, @JsonProperty("addNodesInfos") boolean addNodesInfos, - @JsonProperty("feederArrowSymmetry") boolean feederArrowSymmetry, + @JsonProperty("feederInfoSymmetry") boolean feederInfoSymmetry, @JsonProperty("cssLocation") CssLocation cssLocation, @JsonProperty("svgWidthAndHeightAdded") boolean svgWidthAndHeightAdded, - @JsonProperty("useName") boolean useName) { + @JsonProperty("useName") boolean useName, + @JsonProperty("feederInfosIntraMargin") double feederInfosIntraMargin) { this.diagramPadding = diagramPadding; this.voltageLevelPadding = voltageLevelPadding; this.verticalSpaceBus = verticalSpaceBus; @@ -131,8 +134,8 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve this.drawStraightWires = drawStraightWires; this.horizontalSnakeLinePadding = horizontalSnakeLinePadding; this.verticalSnakeLinePadding = verticalSnakeLinePadding; - this.arrowDistance = arrowDistance; - this.minSpaceForFeederArrows = minSpaceForFeederArrows; + this.feederInfosOuterMargin = feederInfosOuterMargin; + this.spaceForFeederInfos = spaceForFeederInfos; this.diagramName = diagramName; this.avoidSVGComponentsDuplication = avoidSVGComponentsDuplication; this.adaptCellHeightToContent = adaptCellHeightToContent; @@ -144,10 +147,11 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve this.angleLabelShift = angleLabelShift; this.highlightLineState = highlightLineState; this.addNodesInfos = addNodesInfos; - this.feederArrowSymmetry = feederArrowSymmetry; + this.feederInfoSymmetry = feederInfoSymmetry; this.cssLocation = cssLocation; this.svgWidthAndHeightAdded = svgWidthAndHeightAdded; this.useName = useName; + this.feederInfosIntraMargin = feederInfosIntraMargin; } public LayoutParameters(LayoutParameters other) { @@ -167,8 +171,8 @@ public LayoutParameters(LayoutParameters other) { drawStraightWires = other.drawStraightWires; horizontalSnakeLinePadding = other.horizontalSnakeLinePadding; verticalSnakeLinePadding = other.verticalSnakeLinePadding; - arrowDistance = other.arrowDistance; - minSpaceForFeederArrows = other.minSpaceForFeederArrows; + feederInfosOuterMargin = other.feederInfosOuterMargin; + spaceForFeederInfos = other.spaceForFeederInfos; diagramName = other.diagramName; avoidSVGComponentsDuplication = other.avoidSVGComponentsDuplication; adaptCellHeightToContent = other.adaptCellHeightToContent; @@ -181,10 +185,11 @@ public LayoutParameters(LayoutParameters other) { labelCentered = other.labelCentered; highlightLineState = other.highlightLineState; addNodesInfos = other.addNodesInfos; - feederArrowSymmetry = other.feederArrowSymmetry; + feederInfoSymmetry = other.feederInfoSymmetry; cssLocation = other.cssLocation; svgWidthAndHeightAdded = other.svgWidthAndHeightAdded; useName = other.useName; + feederInfosIntraMargin = other.feederInfosIntraMargin; } public double getVerticalSpaceBus() { @@ -304,12 +309,12 @@ public LayoutParameters setVerticalSnakeLinePadding(double verticalSnakeLinePadd return this; } - public double getArrowDistance() { - return arrowDistance; + public double getFeederInfosOuterMargin() { + return feederInfosOuterMargin; } - public LayoutParameters setArrowDistance(double arrowDistance) { - this.arrowDistance = arrowDistance; + public LayoutParameters setFeederInfosOuterMargin(double feederInfosOuterMargin) { + this.feederInfosOuterMargin = feederInfosOuterMargin; return this; } @@ -420,21 +425,21 @@ public LayoutParameters setAddNodesInfos(boolean addNodesInfos) { return this; } - public double getMinSpaceForFeederArrows() { - return minSpaceForFeederArrows; + public double getSpaceForFeederInfos() { + return spaceForFeederInfos; } - public LayoutParameters setMinSpaceForFeederArrows(double minSpaceForFeederArrows) { - this.minSpaceForFeederArrows = minSpaceForFeederArrows; + public LayoutParameters setSpaceForFeederInfos(double spaceForFeederInfos) { + this.spaceForFeederInfos = spaceForFeederInfos; return this; } - public boolean isFeederArrowSymmetry() { - return feederArrowSymmetry; + public boolean isFeederInfoSymmetry() { + return feederInfoSymmetry; } - public LayoutParameters setFeederArrowSymmetry(boolean feederArrowSymmetry) { - this.feederArrowSymmetry = feederArrowSymmetry; + public LayoutParameters setFeederInfoSymmetry(boolean feederInfoSymmetry) { + this.feederInfoSymmetry = feederInfoSymmetry; return this; } @@ -488,6 +493,15 @@ public LayoutParameters setUseName(boolean useName) { return this; } + public double getFeederInfosIntraMargin() { + return feederInfosIntraMargin; + } + + public LayoutParameters setFeederInfosIntraMargin(double feederInfosIntraMargin) { + this.feederInfosIntraMargin = feederInfosIntraMargin; + return this; + } + public enum CssLocation { INSERTED_IN_SVG, EXTERNAL_IMPORTED, EXTERNAL_NO_IMPORT; } diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/PositionVoltageLevelLayout.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/PositionVoltageLevelLayout.java index e75bd7ed7..a35646117 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/PositionVoltageLevelLayout.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/PositionVoltageLevelLayout.java @@ -129,6 +129,6 @@ private void calculateExternCellHeight(LayoutParameters layoutParam) { public static double getFeederSpan(LayoutParameters layoutParam) { // The space needed between the feeder and the node connected to it corresponds to the space for feeder arrows // + half the height of the feeder component + half the height of that node component - return layoutParam.getMinSpaceForFeederArrows() + layoutParam.getMaxComponentHeight(); + return layoutParam.getSpaceForFeederInfos() + layoutParam.getMaxComponentHeight(); } } diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java index d634266e9..84e231e56 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultDiagramLabelProvider.java @@ -64,7 +64,7 @@ public List getFeederInfos(FeederNode node) { default: break; } - if (node.getDirection() == BusCell.Direction.BOTTOM && !layoutParameters.isFeederArrowSymmetry()) { + if (node.getDirection() == BusCell.Direction.BOTTOM && !layoutParameters.isFeederInfoSymmetry()) { Collections.reverse(feederInfos); } return feederInfos; diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java index 67c5b06c1..e0b36034e 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java @@ -788,8 +788,8 @@ protected void transformFeederInfo(List points, ComponentSize componentSi // If not enough space to have layoutParameters.getArrowDistance() at both sides of the 2 feeder infos, // we compute the distance between feeder anchor and first feeder info so that the two feeder infos are centered. double distFeederAnchorToFirstFeederInfoCenter = - distancePoints >= 2 * layoutParameters.getArrowDistance() + 2 * componentSize.getHeight() - ? layoutParameters.getArrowDistance() + distancePoints >= 2 * layoutParameters.getFeederInfosOuterMargin() + 2 * componentSize.getHeight() + ? layoutParameters.getFeederInfosOuterMargin() : (distancePoints - 2 * componentSize.getHeight()) / 2; double x = pointA.getX() + cosAngle * (distFeederAnchorToFirstFeederInfoCenter + shift); double y = pointA.getY() + sinAngle * (distFeederAnchorToFirstFeederInfoCenter + shift); diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java index 54c5b3852..3731cf658 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java @@ -72,7 +72,7 @@ public List getFeederInfos(FeederNode node) { new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "30", null), new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "40", null), new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "50", null)); - boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederArrowSymmetry(); + boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederInfoSymmetry(); if (!feederArrowSymmetry) { Collections.reverse(feederInfos); } @@ -91,7 +91,7 @@ public void test() { // build graph VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId(), true); - layoutParameters.setMinSpaceForFeederArrows(120); + layoutParameters.setSpaceForFeederInfos(120); // Run layout voltageLevelGraphLayout(g); diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java index ea5245be1..5837591a9 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestSVGWriter.java @@ -660,7 +660,7 @@ public List getFeederInfos(FeederNode node) { List feederInfos = Arrays.asList( new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "10", null), new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "20", null)); - boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederArrowSymmetry(); + boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederInfoSymmetry(); if (!feederArrowSymmetry) { Collections.reverse(feederInfos); } @@ -732,7 +732,7 @@ public void testSubstation() { @Test public void testSubstationArrowSymmetry() { // SVG file generation for substation with symmetric feeder arrow and comparison to reference - layoutParameters.setFeederArrowSymmetry(true); + layoutParameters.setFeederInfoSymmetry(true); assertEquals(toString("/substation_feeder_arrow_symmetry.svg"), toSVG(substG, "/substation_feeder_arrow_symmetry.svg", initValueProvider, new BasicStyleProvider())); } diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java index 0decbaa6d..046991535 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/layout/LayoutParametersTest.java @@ -34,7 +34,7 @@ public void test() { .setDrawStraightWires(true) .setHorizontalSnakeLinePadding(25) .setVerticalSnakeLinePadding(40) - .setArrowDistance(25) + .setFeederInfosOuterMargin(25) .setDiagramName("diag") .setAvoidSVGComponentsDuplication(true) .setAdaptCellHeightToContent(true) @@ -47,10 +47,13 @@ public void test() { .setHighlightLineState(false) .setTooltipEnabled(true) .setAddNodesInfos(true) - .setMinSpaceForFeederArrows(70) - .setFeederArrowSymmetry(true) + .setSpaceForFeederInfos(70) + .setFeederInfoSymmetry(true) .setCssLocation(LayoutParameters.CssLocation.EXTERNAL_NO_IMPORT) - .setSvgWidthAndHeightAdded(true); + .setSvgWidthAndHeightAdded(true) + .setUseName(true) + .setFeederInfosIntraMargin(21); + LayoutParameters layoutParameters2 = new LayoutParameters(layoutParameters); assertEquals(layoutParameters.getVoltageLevelPadding().getLeft(), layoutParameters2.getVoltageLevelPadding().getLeft(), 0); @@ -73,7 +76,7 @@ public void test() { assertEquals(layoutParameters.isDrawStraightWires(), layoutParameters2.isDrawStraightWires()); assertEquals(layoutParameters.getHorizontalSnakeLinePadding(), layoutParameters2.getHorizontalSnakeLinePadding(), 0); assertEquals(layoutParameters.getVerticalSnakeLinePadding(), layoutParameters2.getVerticalSnakeLinePadding(), 0); - assertEquals(layoutParameters.getArrowDistance(), layoutParameters2.getArrowDistance(), 0); + assertEquals(layoutParameters.getFeederInfosOuterMargin(), layoutParameters2.getFeederInfosOuterMargin(), 0); assertEquals(layoutParameters.getDiagramName(), layoutParameters2.getDiagramName()); assertEquals(layoutParameters.isAvoidSVGComponentsDuplication(), layoutParameters2.isAvoidSVGComponentsDuplication()); assertEquals(layoutParameters.isAdaptCellHeightToContent(), layoutParameters2.isAdaptCellHeightToContent()); @@ -86,9 +89,11 @@ public void test() { assertEquals(layoutParameters.isHighlightLineState(), layoutParameters2.isHighlightLineState()); assertEquals(layoutParameters.isTooltipEnabled(), layoutParameters2.isTooltipEnabled()); assertEquals(layoutParameters.isAddNodesInfos(), layoutParameters2.isAddNodesInfos()); - assertEquals(layoutParameters.getMinSpaceForFeederArrows(), layoutParameters2.getMinSpaceForFeederArrows(), 0); - assertEquals(layoutParameters.isFeederArrowSymmetry(), layoutParameters2.isFeederArrowSymmetry()); + 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); } } diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java index 49dca33a1..7f8380e4d 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/svg/FeederInfoProviderTest.java @@ -33,7 +33,7 @@ public class FeederInfoProviderTest extends AbstractTestCaseIidm { @Before public void setUp() { - layoutParameters.setFeederArrowSymmetry(true); + layoutParameters.setFeederInfoSymmetry(true); network = Network.create("testCase1", "test"); graphBuilder = new NetworkGraphBuilder(network); substation = network.newSubstation().setId("s").setCountry(Country.FR).add(); @@ -99,7 +99,7 @@ public void setUp() { @Test public void test() { ComponentLibrary componentLibrary = new ConvergenceComponentLibrary(); - layoutParameters.setFeederArrowSymmetry(true); + layoutParameters.setFeederInfoSymmetry(true); VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId(), true); new SmartVoltageLevelLayoutFactory(network).create(g).run(layoutParameters); // to have cell orientations (bottom / up) toSVG(g, "test.svg"); @@ -155,7 +155,7 @@ public void test() { assertTrue(feederInfos4.get(1).getDirection().isPresent()); // Reverse order - layoutParameters.setFeederArrowSymmetry(false); + layoutParameters.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-core/src/test/resources/TestSldClassSubstationMetadata.json b/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json index 07d2febe1..2bfbae215 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json +++ b/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json @@ -576,8 +576,8 @@ "drawStraightWires" : false, "horizontalSnakeLinePadding" : 20.0, "verticalSnakeLinePadding" : 25.0, - "arrowDistance" : 20.0, - "minSpaceForFeederArrows" : 50.0, + "feederInfosOuterMargin" : 20.0, + "spaceForFeederInfos" : 50.0, "diagramName" : null, "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : true, @@ -589,9 +589,10 @@ "angleLabelShift" : 15.0, "highlightLineState" : true, "addNodesInfos" : false, - "feederArrowSymmetry" : false, + "feederInfoSymmetry" : false, "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : false, - "useName" : false + "useName" : false, + "feederInfosIntraMargin" : 20.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json b/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json index 3b8b45af6..10cb64375 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json +++ b/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json @@ -328,8 +328,8 @@ "drawStraightWires" : false, "horizontalSnakeLinePadding" : 20.0, "verticalSnakeLinePadding" : 25.0, - "arrowDistance" : 20.0, - "minSpaceForFeederArrows" : 50.0, + "feederInfosOuterMargin" : 20.0, + "spaceForFeederInfos" : 50.0, "diagramName" : null, "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : true, @@ -341,9 +341,10 @@ "angleLabelShift" : 15.0, "highlightLineState" : true, "addNodesInfos" : false, - "feederArrowSymmetry" : false, + "feederInfoSymmetry" : false, "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : false, - "useName" : false + "useName" : false, + "feederInfosIntraMargin" : 20.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/substDiag_metadata.json b/single-line-diagram-core/src/test/resources/substDiag_metadata.json index 95b436df2..ec9c18070 100644 --- a/single-line-diagram-core/src/test/resources/substDiag_metadata.json +++ b/single-line-diagram-core/src/test/resources/substDiag_metadata.json @@ -3035,8 +3035,8 @@ "drawStraightWires" : false, "horizontalSnakeLinePadding" : 30.0, "verticalSnakeLinePadding" : 30.0, - "arrowDistance" : 20.0, - "minSpaceForFeederArrows" : 50.0, + "feederInfosOuterMargin" : 20.0, + "spaceForFeederInfos" : 50.0, "diagramName" : null, "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : false, @@ -3048,9 +3048,10 @@ "angleLabelShift" : 15.0, "highlightLineState" : true, "addNodesInfos" : false, - "feederArrowSymmetry" : false, + "feederInfoSymmetry" : false, "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : true, - "useName" : true + "useName" : true, + "feederInfosIntraMargin" : 20.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json b/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json index 16a351b81..be35126d8 100644 --- a/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json +++ b/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json @@ -3232,8 +3232,8 @@ "drawStraightWires" : false, "horizontalSnakeLinePadding" : 20.0, "verticalSnakeLinePadding" : 25.0, - "arrowDistance" : 20.0, - "minSpaceForFeederArrows" : 50.0, + "feederInfosOuterMargin" : 20.0, + "spaceForFeederInfos" : 50.0, "diagramName" : null, "avoidSVGComponentsDuplication" : false, "adaptCellHeightToContent" : false, @@ -3245,8 +3245,10 @@ "angleLabelShift" : 15.0, "highlightLineState" : true, "addNodesInfos" : false, - "feederArrowSymmetry" : false, + "feederInfoSymmetry" : false, "cssLocation" : "EXTERNAL_IMPORTED", - "svgWidthAndHeightAdded" : false + "svgWidthAndHeightAdded" : false, + "useName" : false, + "feederInfosIntraMargin" : 20.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/vlDiag_metadata.json b/single-line-diagram-core/src/test/resources/vlDiag_metadata.json index 0fb9186fc..f940cfa23 100644 --- a/single-line-diagram-core/src/test/resources/vlDiag_metadata.json +++ b/single-line-diagram-core/src/test/resources/vlDiag_metadata.json @@ -1516,8 +1516,8 @@ "drawStraightWires" : false, "horizontalSnakeLinePadding" : 30.0, "verticalSnakeLinePadding" : 30.0, - "arrowDistance" : 20.0, - "minSpaceForFeederArrows" : 50.0, + "feederInfosOuterMargin" : 20.0, + "spaceForFeederInfos" : 50.0, "diagramName" : null, "avoidSVGComponentsDuplication" : true, "adaptCellHeightToContent" : false, @@ -1529,9 +1529,10 @@ "angleLabelShift" : 15.0, "highlightLineState" : true, "addNodesInfos" : true, - "feederArrowSymmetry" : false, + "feederInfoSymmetry" : false, "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : true, - "useName" : true + "useName" : true, + "feederInfosIntraMargin" : 20.0 } } \ No newline at end of file From dc68170e385b69f76d7e9024dcf9f66f35ec90fe Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Tue, 25 Jan 2022 15:41:38 +0100 Subject: [PATCH 6/7] Use new LayoutParameter feederInfosIntraMargin Signed-off-by: Thomas ADAM --- .../powsybl/sld/layout/LayoutParameters.java | 2 +- .../com/powsybl/sld/svg/DefaultSVGWriter.java | 10 +++++----- .../com/powsybl/sld/AbstractTestCase.java | 5 +++-- .../sld/iidm/TestCase14UpToNFeederInfos.java | 5 +++-- .../resources/TestCase14UpToNFeederInfos.svg | 19 +++++++------------ .../TestSldClassSubstationMetadata.json | 2 +- .../resources/TestSldClassVlMetadata.json | 2 +- .../test/resources/substDiag_metadata.json | 2 +- ...stDiag_metadata_nominal_voltage_style.json | 2 +- .../src/test/resources/vlDiag_metadata.json | 2 +- 10 files changed, 24 insertions(+), 27 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java index a46c5d53e..229d9ad55 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/LayoutParameters.java @@ -76,7 +76,7 @@ public class LayoutParameters { private boolean useName = false; - private double feederInfosIntraMargin = 20; + private double feederInfosIntraMargin = 10; @JsonIgnore private Map componentsSize; diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java index e0b36034e..9f81f446c 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java @@ -851,15 +851,15 @@ protected void insertFeederInfos(String prefixId, points.add(new Point(feederNode.getDiagramCoordinates())); } - int iFeederInfo = 0; + double shiftFeederInfo2 = 0; for (FeederInfo feederInfo : initProvider.getFeederInfos(feederNode)) { - // Compute shifting even if not displayed to ensure aligned feeder info - double height = componentLibrary.getSize(feederInfo.getComponentType()).getHeight(); - double shiftFeederInfo = iFeederInfo++ * 2 * height; if (!feederInfo.isEmpty()) { - drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftFeederInfo, metadata); + drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftFeederInfo2, metadata); addFeederInfoComponentMetadata(metadata, feederInfo.getComponentType()); } + // Compute shifting even if not displayed to ensure aligned feeder info + double height = componentLibrary.getSize(feederInfo.getComponentType()).getHeight(); + shiftFeederInfo2 += layoutParameters.getFeederInfosIntraMargin() + height; } } diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java index 652e97f75..c1a66d966 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/AbstractTestCase.java @@ -55,13 +55,14 @@ private static LayoutParameters createDefaultLayoutParameters() { .setShowGrid(true) .setShowInternalNodes(true) .setScaleFactor(1) - .setArrowDistance(20) + .setFeederInfosOuterMargin(20) .setDrawStraightWires(false) .setHorizontalSnakeLinePadding(30) .setVerticalSnakeLinePadding(30) .setCssLocation(LayoutParameters.CssLocation.INSERTED_IN_SVG) .setSvgWidthAndHeightAdded(true) - .setUseName(true); + .setUseName(true) + .setFeederInfosIntraMargin(10); } protected ResourcesComponentLibrary getResourcesComponentLibrary() { diff --git a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java index 3731cf658..4236a2bda 100644 --- a/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java +++ b/single-line-diagram-core/src/test/java/com/powsybl/sld/iidm/TestCase14UpToNFeederInfos.java @@ -70,7 +70,7 @@ public List getFeederInfos(FeederNode node) { new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "10", null), new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "20", null), new FeederInfo(ARROW_REACTIVE, Direction.IN, null, "30", null), - new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "40", null), + new FeederInfo(ARROW_ACTIVE, null, null, "40", null), // Not displayed new FeederInfo(ARROW_ACTIVE, Direction.OUT, null, "50", null)); boolean feederArrowSymmetry = node.getDirection() == BusCell.Direction.TOP || layoutParameters.isFeederInfoSymmetry(); if (!feederArrowSymmetry) { @@ -91,7 +91,8 @@ public void test() { // build graph VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId(), true); - layoutParameters.setSpaceForFeederInfos(120); + layoutParameters.setSpaceForFeederInfos(100) + .setFeederInfosIntraMargin(5); // Run layout voltageLevelGraphLayout(g); diff --git a/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg index f66d49219..1f2e6f99f 100644 --- a/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg +++ b/single-line-diagram-core/src/test/resources/TestCase14UpToNFeederInfos.svg @@ -69,7 +69,7 @@ - + @@ -85,35 +85,30 @@ - + - + - + 10 - + 20 - + 30 - - - 40 - - 50 @@ -122,7 +117,7 @@ - + diff --git a/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json b/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json index 2bfbae215..2a1fe72c1 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json +++ b/single-line-diagram-core/src/test/resources/TestSldClassSubstationMetadata.json @@ -593,6 +593,6 @@ "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : false, "useName" : false, - "feederInfosIntraMargin" : 20.0 + "feederInfosIntraMargin" : 10.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json b/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json index 10cb64375..6450aee78 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json +++ b/single-line-diagram-core/src/test/resources/TestSldClassVlMetadata.json @@ -345,6 +345,6 @@ "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : false, "useName" : false, - "feederInfosIntraMargin" : 20.0 + "feederInfosIntraMargin" : 10.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/substDiag_metadata.json b/single-line-diagram-core/src/test/resources/substDiag_metadata.json index ec9c18070..cdbf8c168 100644 --- a/single-line-diagram-core/src/test/resources/substDiag_metadata.json +++ b/single-line-diagram-core/src/test/resources/substDiag_metadata.json @@ -3052,6 +3052,6 @@ "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : true, "useName" : true, - "feederInfosIntraMargin" : 20.0 + "feederInfosIntraMargin" : 10.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json b/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json index be35126d8..9d1eb6719 100644 --- a/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json +++ b/single-line-diagram-core/src/test/resources/substDiag_metadata_nominal_voltage_style.json @@ -3249,6 +3249,6 @@ "cssLocation" : "EXTERNAL_IMPORTED", "svgWidthAndHeightAdded" : false, "useName" : false, - "feederInfosIntraMargin" : 20.0 + "feederInfosIntraMargin" : 10.0 } } \ No newline at end of file diff --git a/single-line-diagram-core/src/test/resources/vlDiag_metadata.json b/single-line-diagram-core/src/test/resources/vlDiag_metadata.json index f940cfa23..2a167ce11 100644 --- a/single-line-diagram-core/src/test/resources/vlDiag_metadata.json +++ b/single-line-diagram-core/src/test/resources/vlDiag_metadata.json @@ -1533,6 +1533,6 @@ "cssLocation" : "INSERTED_IN_SVG", "svgWidthAndHeightAdded" : true, "useName" : true, - "feederInfosIntraMargin" : 20.0 + "feederInfosIntraMargin" : 10.0 } } \ No newline at end of file From a914ce8ae4fb5611cd42fe7c30541926db929a32 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Wed, 26 Jan 2022 10:46:18 +0100 Subject: [PATCH 7/7] Taking into account PR reviews comments Signed-off-by: Thomas ADAM --- .../com/powsybl/sld/svg/DefaultSVGWriter.java | 16 +++------ .../resources/InternalBranchesBusBreaker.svg | 12 +++---- .../resources/InternalBranchesNodeBreaker.svg | 12 +++---- .../NodeDecoratorsBranchStatusBusBreaker.svg | 12 +++---- .../NodeDecoratorsBranchStatusNodeBreaker.svg | 12 +++---- .../test/resources/NodeDecoratorsSwitches.svg | 12 +++---- .../src/test/resources/TestCase1.svg | 4 +-- ...ase12GraphWithNodesInfosNominalVoltage.svg | 36 +++++++++---------- ...stCase12GraphWithNodesInfosTopological.svg | 36 +++++++++---------- .../test/resources/TestSldClassSubstation.svg | 8 ++--- .../src/test/resources/TestSldClassVl.svg | 8 ++--- 11 files changed, 81 insertions(+), 87 deletions(-) diff --git a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java index 9f81f446c..f10547033 100644 --- a/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java +++ b/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/DefaultSVGWriter.java @@ -785,14 +785,8 @@ protected void transformFeederInfo(List points, ComponentSize componentSi double cosAngle = dx / distancePoints; double sinAngle = dy / distancePoints; - // If not enough space to have layoutParameters.getArrowDistance() at both sides of the 2 feeder infos, - // we compute the distance between feeder anchor and first feeder info so that the two feeder infos are centered. - double distFeederAnchorToFirstFeederInfoCenter = - distancePoints >= 2 * layoutParameters.getFeederInfosOuterMargin() + 2 * componentSize.getHeight() - ? layoutParameters.getFeederInfosOuterMargin() - : (distancePoints - 2 * componentSize.getHeight()) / 2; - double x = pointA.getX() + cosAngle * (distFeederAnchorToFirstFeederInfoCenter + shift); - double y = pointA.getY() + sinAngle * (distFeederAnchorToFirstFeederInfoCenter + shift); + double x = pointA.getX() + cosAngle * (layoutParameters.getFeederInfosOuterMargin() + shift); + double y = pointA.getY() + sinAngle * (layoutParameters.getFeederInfosOuterMargin() + shift); double feederInfoRotationAngle = Math.atan(dy / dx) - Math.PI / 2; if (feederInfoRotationAngle < -Math.PI / 2) { @@ -851,15 +845,15 @@ protected void insertFeederInfos(String prefixId, points.add(new Point(feederNode.getDiagramCoordinates())); } - double shiftFeederInfo2 = 0; + double shiftFeederInfo = 0; for (FeederInfo feederInfo : initProvider.getFeederInfos(feederNode)) { if (!feederInfo.isEmpty()) { - drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftFeederInfo2, metadata); + drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftFeederInfo, metadata); addFeederInfoComponentMetadata(metadata, feederInfo.getComponentType()); } // Compute shifting even if not displayed to ensure aligned feeder info double height = componentLibrary.getSize(feederInfo.getComponentType()).getHeight(); - shiftFeederInfo2 += layoutParameters.getFeederInfosIntraMargin() + height; + shiftFeederInfo += layoutParameters.getFeederInfosIntraMargin() + height; } } diff --git a/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg b/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg index 1ecc94b84..1f47775c5 100644 --- a/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg +++ b/single-line-diagram-core/src/test/resources/InternalBranchesBusBreaker.svg @@ -157,12 +157,12 @@ - + 0 - + 0 @@ -358,12 +358,12 @@ - + 0 - + 0 @@ -468,12 +468,12 @@ - + 0 - + 0 diff --git a/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg b/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg index 2e2d01ed6..867483832 100644 --- a/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg +++ b/single-line-diagram-core/src/test/resources/InternalBranchesNodeBreaker.svg @@ -148,12 +148,12 @@ - + 0 - + 0 @@ -389,12 +389,12 @@ - + 0 - + 0 @@ -523,12 +523,12 @@ - + 375 - + 48 diff --git a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg index 18706c845..1e26d74f1 100644 --- a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg +++ b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusBusBreaker.svg @@ -143,12 +143,12 @@ - + 0 - + 0 @@ -356,12 +356,12 @@ - + 0 - + 0 @@ -475,12 +475,12 @@ - + 0 - + 0 diff --git a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg index 03269bd52..4c0df6247 100644 --- a/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg +++ b/single-line-diagram-core/src/test/resources/NodeDecoratorsBranchStatusNodeBreaker.svg @@ -160,12 +160,12 @@ - + 0 - + 0 @@ -395,12 +395,12 @@ - + 0 - + 0 @@ -650,12 +650,12 @@ - + 0 - + 0 diff --git a/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg b/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg index 1c085b2f8..3b4b015d1 100644 --- a/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg +++ b/single-line-diagram-core/src/test/resources/NodeDecoratorsSwitches.svg @@ -157,12 +157,12 @@ - + 0 - + 0 @@ -428,12 +428,12 @@ - + 0 - + 0 @@ -580,12 +580,12 @@ - + 375 - + 48 diff --git a/single-line-diagram-core/src/test/resources/TestCase1.svg b/single-line-diagram-core/src/test/resources/TestCase1.svg index 79cf3dcec..a5cbff5b8 100644 --- a/single-line-diagram-core/src/test/resources/TestCase1.svg +++ b/single-line-diagram-core/src/test/resources/TestCase1.svg @@ -93,13 +93,13 @@ - + tata - + tutu diff --git a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg index a21daa0c9..94be26595 100644 --- a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg +++ b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosNominalVoltage.svg @@ -198,12 +198,12 @@ - + 0 - + 0 @@ -244,12 +244,12 @@ - + 0 - + 0 @@ -290,12 +290,12 @@ - + 0 - + 0 @@ -399,12 +399,12 @@ - + 0 - + 0 @@ -445,12 +445,12 @@ - + 0 - + 0 @@ -554,12 +554,12 @@ - + 0 - + 0 @@ -600,12 +600,12 @@ - + 0 - + 0 @@ -709,12 +709,12 @@ - + 0 - + 0 @@ -755,12 +755,12 @@ - + 0 - + 0 diff --git a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg index 178daba40..4e7cfa0e6 100644 --- a/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg +++ b/single-line-diagram-core/src/test/resources/TestCase12GraphWithNodesInfosTopological.svg @@ -262,12 +262,12 @@ - + 0 - + 0 @@ -308,12 +308,12 @@ - + 0 - + 0 @@ -354,12 +354,12 @@ - + 0 - + 0 @@ -463,12 +463,12 @@ - + 0 - + 0 @@ -509,12 +509,12 @@ - + 0 - + 0 @@ -618,12 +618,12 @@ - + 0 - + 0 @@ -664,12 +664,12 @@ - + 0 - + 0 @@ -773,12 +773,12 @@ - + 0 - + 0 @@ -819,12 +819,12 @@ - + 0 - + 0 diff --git a/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg b/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg index 3ce1e9fa8..a04b4371c 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg +++ b/single-line-diagram-core/src/test/resources/TestSldClassSubstation.svg @@ -166,12 +166,12 @@ - + 0 - + 0 @@ -264,12 +264,12 @@ - + 0 - + 0 diff --git a/single-line-diagram-core/src/test/resources/TestSldClassVl.svg b/single-line-diagram-core/src/test/resources/TestSldClassVl.svg index d494f2874..db3443162 100644 --- a/single-line-diagram-core/src/test/resources/TestSldClassVl.svg +++ b/single-line-diagram-core/src/test/resources/TestSldClassVl.svg @@ -163,12 +163,12 @@ - + 0 - + 0 @@ -209,12 +209,12 @@ - + 0 - + 0