diff --git a/diagram-test/src/main/java/com/powsybl/diagram/test/Networks.java b/diagram-test/src/main/java/com/powsybl/diagram/test/Networks.java index 5cfac0818..c0b21193f 100644 --- a/diagram-test/src/main/java/com/powsybl/diagram/test/Networks.java +++ b/diagram-test/src/main/java/com/powsybl/diagram/test/Networks.java @@ -140,7 +140,7 @@ public static Network createNetworkWithLine() { .setId("Bus1") .add(); Substation substation2 = network.newSubstation() - .setId("Substation2") + .setId(SUBSTATION_2_ID) .setCountry(Country.FR) .add(); VoltageLevel voltageLevel2 = substation2.newVoltageLevel() diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalLayoutUtil.java similarity index 95% rename from single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalLayout.java rename to single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalLayoutUtil.java index 86e25ac40..5e6c048d2 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalLayoutUtil.java @@ -17,9 +17,9 @@ /** * @author Thomas Adam */ -public final class HorizontalLayout { +public final class HorizontalLayoutUtil { - private HorizontalLayout() { + private HorizontalLayoutUtil() { } public static double computeCoordY(AbstractBaseGraph graph, LayoutParameters layoutParameters, double topPadding, VoltageLevelGraph vlGraph) { @@ -67,7 +67,7 @@ public static void adaptPaddingToSnakeLines(AbstractBaseGraph graph, LayoutParam for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { x += AbstractLayout.getWidthVerticalSnakeLines(vlGraph.getId(), layoutParameters, infosNbSnakeLines); - vlGraph.setCoord(x + voltageLevelPadding.getLeft(), HorizontalLayout.computeCoordY(graph, layoutParameters, topPadding, vlGraph)); + vlGraph.setCoord(x + voltageLevelPadding.getLeft(), HorizontalLayoutUtil.computeCoordY(graph, layoutParameters, topPadding, vlGraph)); x += vlGraph.getWidth(); } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalSubstationLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalSubstationLayout.java index 359785d9b..05b407b2d 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalSubstationLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalSubstationLayout.java @@ -53,7 +53,7 @@ protected void calculateCoordVoltageLevels(LayoutParameters layoutParameters) { vLayout.run(layoutParameters); x += voltageLevelPadding.getLeft(); - vlGraph.setCoord(x, HorizontalLayout.computeCoordY(getGraph(), layoutParameters, topPadding, vlGraph)); + vlGraph.setCoord(x, HorizontalLayoutUtil.computeCoordY(getGraph(), layoutParameters, topPadding, vlGraph)); x += vlGraph.getWidth() + voltageLevelPadding.getRight(); substationHeight = Math.max(substationHeight, vlGraph.getHeight()); @@ -72,7 +72,7 @@ public void manageSnakeLines(LayoutParameters layoutParameters) { } private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) { - HorizontalLayout.adaptPaddingToSnakeLines(getGraph(), layoutParameters, infosNbSnakeLines); + HorizontalLayoutUtil.adaptPaddingToSnakeLines(getGraph(), layoutParameters, infosNbSnakeLines); getGraph().getVoltageLevels().forEach(g -> manageSnakeLines(g, layoutParameters)); manageSnakeLines(getGraph(), layoutParameters); diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalZoneLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalZoneLayout.java index ca5a5d62b..f48ebb2c9 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalZoneLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/HorizontalZoneLayout.java @@ -68,7 +68,7 @@ public void manageSnakeLines(LayoutParameters layoutParameters) { } private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) { - HorizontalLayout.adaptPaddingToSnakeLines(getGraph(), layoutParameters, infosNbSnakeLines); + HorizontalLayoutUtil.adaptPaddingToSnakeLines(getGraph(), layoutParameters, infosNbSnakeLines); manageAllSnakeLines(layoutParameters); } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalLayout.java index 701d96307..af9b2d703 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalLayout.java @@ -7,86 +7,15 @@ */ package com.powsybl.sld.layout; -import com.powsybl.sld.model.coordinate.Direction; -import com.powsybl.sld.model.coordinate.Side; -import com.powsybl.sld.model.graphs.AbstractBaseGraph; -import com.powsybl.sld.model.graphs.BaseGraph; -import com.powsybl.sld.model.graphs.VoltageLevelGraph; +import com.powsybl.sld.model.coordinate.Point; import com.powsybl.sld.model.nodes.Node; import java.util.List; -import static com.powsybl.sld.model.coordinate.Direction.BOTTOM; -import static com.powsybl.sld.model.coordinate.Direction.TOP; - /** * @author Thomas Adam */ -public final class VerticalLayout { - - private VerticalLayout() { - } - - public static void adaptPaddingToSnakeLines(AbstractBaseGraph graph, LayoutParameters layoutParameters, InfosNbSnakeLinesVertical infosNbSnakeLines) { - double widthSnakeLinesLeft = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.LEFT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding(); - - LayoutParameters.Padding diagramPadding = layoutParameters.getDiagramPadding(); - LayoutParameters.Padding voltageLevelPadding = layoutParameters.getVoltageLevelPadding(); - - double xVoltageLevels = widthSnakeLinesLeft + diagramPadding.getLeft() + voltageLevelPadding.getLeft(); - double y = diagramPadding.getTop() - + graph.getVoltageLevelStream().findFirst().map(vlg -> getHeightHorizontalSnakeLines(vlg.getId(), TOP, layoutParameters, infosNbSnakeLines)).orElse(0.); - - for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { - vlGraph.setCoord(xVoltageLevels, y + voltageLevelPadding.getTop()); - y += vlGraph.getHeight() + getHeightHorizontalSnakeLines(vlGraph.getId(), BOTTOM, layoutParameters, infosNbSnakeLines); - } - - double widthSnakeLinesRight = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.RIGHT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding(); - double substationWidth = graph.getWidth() + widthSnakeLinesLeft + widthSnakeLinesRight; - double substationHeight = y - diagramPadding.getTop(); - graph.setSize(substationWidth, substationHeight); - - infosNbSnakeLines.reset(); - } - - private static double getHeightHorizontalSnakeLines(String vlGraphId, Direction direction, LayoutParameters layoutParameters, InfosNbSnakeLinesVertical infosNbSnakeLines) { - return Math.max(infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(vlGraphId, direction) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding(); - } - - public static double getVerticalShift(LayoutParameters layoutParam, Direction dNode1, int nbSnakeLines1) { - return (nbSnakeLines1 - 1) * layoutParam.getVerticalSnakeLinePadding() - + (dNode1 == Direction.TOP ? layoutParam.getVoltageLevelPadding().getTop() : layoutParam.getVoltageLevelPadding().getBottom()); - } - - /** - * Dispatching the snake lines to the right and to the left - */ - public static Side getSide(boolean increment) { - return increment ? Side.LEFT : Side.RIGHT; - } - - public static double getXSnakeLine(BaseGraph graph, Node node, Side side, LayoutParameters layoutParam, InfosNbSnakeLinesVertical infosNbSnakeLines, double maxVoltageLevelWidth) { - double shiftLeftRight = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().compute(side, (k, v) -> v + 1) - 1, 0) * layoutParam.getHorizontalSnakeLinePadding(); - return graph.getVoltageLevelGraph(node).getX() - layoutParam.getVoltageLevelPadding().getLeft() - + (side == Side.LEFT ? -shiftLeftRight : shiftLeftRight + maxVoltageLevelWidth); - } +public interface VerticalLayout { - public static double getYSnakeLine(BaseGraph graph, Node node, Direction dNode1, double decalV, LayoutParameters layoutParam) { - double y = graph.getShiftedPoint(node).getY(); - if (dNode1 == BOTTOM) { - return y + decalV; - } else { - List vls = graph.getVoltageLevels(); - int iVl = vls.indexOf(graph.getVoltageLevelGraph(node)); - if (iVl == 0) { - return y - decalV; - } else { - VoltageLevelGraph vlAbove = vls.get(iVl - 1); - return vlAbove.getY() - + vlAbove.getHeight() - layoutParam.getVoltageLevelPadding().getTop() - layoutParam.getVoltageLevelPadding().getBottom() - + decalV; - } - } - } + void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node node2, boolean increment, List polyline); } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalLayoutUtil.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalLayoutUtil.java new file mode 100644 index 000000000..79eac2314 --- /dev/null +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalLayoutUtil.java @@ -0,0 +1,135 @@ +/** + * 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.sld.model.coordinate.Direction; +import com.powsybl.sld.model.coordinate.Point; +import com.powsybl.sld.model.coordinate.Side; +import com.powsybl.sld.model.graphs.AbstractBaseGraph; +import com.powsybl.sld.model.graphs.BaseGraph; +import com.powsybl.sld.model.graphs.VoltageLevelGraph; +import com.powsybl.sld.model.nodes.Node; + +import java.util.ArrayList; +import java.util.List; + +import static com.powsybl.sld.model.coordinate.Direction.BOTTOM; +import static com.powsybl.sld.model.coordinate.Direction.TOP; + +/** + * @author Thomas Adam + */ +public final class VerticalLayoutUtil { + + private VerticalLayoutUtil() { + } + + public static void adaptPaddingToSnakeLines(AbstractBaseGraph graph, LayoutParameters layoutParameters, InfosNbSnakeLinesVertical infosNbSnakeLines) { + double widthSnakeLinesLeft = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.LEFT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding(); + + LayoutParameters.Padding diagramPadding = layoutParameters.getDiagramPadding(); + LayoutParameters.Padding voltageLevelPadding = layoutParameters.getVoltageLevelPadding(); + + double xVoltageLevels = widthSnakeLinesLeft + diagramPadding.getLeft() + voltageLevelPadding.getLeft(); + double y = diagramPadding.getTop() + + graph.getVoltageLevelStream().findFirst().map(vlg -> getHeightHorizontalSnakeLines(vlg.getId(), TOP, layoutParameters, infosNbSnakeLines)).orElse(0.); + + for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) { + vlGraph.setCoord(xVoltageLevels, y + voltageLevelPadding.getTop()); + y += vlGraph.getHeight() + getHeightHorizontalSnakeLines(vlGraph.getId(), BOTTOM, layoutParameters, infosNbSnakeLines); + } + + double widthSnakeLinesRight = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.RIGHT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding(); + double substationWidth = graph.getWidth() + widthSnakeLinesLeft + widthSnakeLinesRight; + double substationHeight = y - diagramPadding.getTop(); + graph.setSize(substationWidth, substationHeight); + + infosNbSnakeLines.reset(); + } + + private static double getHeightHorizontalSnakeLines(String vlGraphId, Direction direction, LayoutParameters layoutParameters, InfosNbSnakeLinesVertical infosNbSnakeLines) { + return Math.max(infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(vlGraphId, direction) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding(); + } + + public static double getVerticalShift(LayoutParameters layoutParam, Direction dNode1, int nbSnakeLines1) { + return (nbSnakeLines1 - 1) * layoutParam.getVerticalSnakeLinePadding() + + (dNode1 == Direction.TOP ? layoutParam.getVoltageLevelPadding().getTop() : layoutParam.getVoltageLevelPadding().getBottom()); + } + + /** + * Dispatching the snake lines to the right and to the left + */ + public static Side getSide(boolean increment) { + return increment ? Side.LEFT : Side.RIGHT; + } + + public static double getXSnakeLine(BaseGraph graph, Node node, Side side, LayoutParameters layoutParam, InfosNbSnakeLinesVertical infosNbSnakeLines, double maxVoltageLevelWidth) { + double shiftLeftRight = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().compute(side, (k, v) -> v + 1) - 1, 0) * layoutParam.getHorizontalSnakeLinePadding(); + return graph.getVoltageLevelGraph(node).getX() - layoutParam.getVoltageLevelPadding().getLeft() + + (side == Side.LEFT ? -shiftLeftRight : shiftLeftRight + maxVoltageLevelWidth); + } + + public static double getYSnakeLine(BaseGraph graph, Node node, Direction dNode1, double decalV, LayoutParameters layoutParam) { + double y = graph.getShiftedPoint(node).getY(); + if (dNode1 == BOTTOM) { + return y + decalV; + } else { + List vls = graph.getVoltageLevels(); + int iVl = vls.indexOf(graph.getVoltageLevelGraph(node)); + if (iVl == 0) { + return y - decalV; + } else { + VoltageLevelGraph vlAbove = vls.get(iVl - 1); + return vlAbove.getY() + + vlAbove.getHeight() - layoutParam.getVoltageLevelPadding().getTop() - layoutParam.getVoltageLevelPadding().getBottom() + + decalV; + } + } + } + + public static List calculatePolylineSnakeLine(VerticalLayout layout, + BaseGraph graph, InfosNbSnakeLinesVertical infosNbSnakeLines, + LayoutParameters layoutParam, Node node1, Node node2, + boolean increment) { + List polyline; + if (graph.getVoltageLevelGraph(node1) == graph.getVoltageLevelGraph(node2)) { // in the same VL (so far always horizontal layout) + VoltageLevelGraph vlGraph = graph.getVoltageLevelGraph(node1); + String graphId = vlGraph.getId(); + + InfosNbSnakeLinesHorizontal infosNbSnakeLinesH = InfosNbSnakeLinesHorizontal.create(vlGraph); + + // Reset the horizontal layout numbers to current graph numbers + int currentNbBottom = infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(graphId, BOTTOM); + int currentNbTop = infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(graphId, TOP); + int currentNbLeft = infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.LEFT); + infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(BOTTOM, currentNbBottom); + infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(TOP, currentNbTop); + infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().put(graphId, currentNbLeft); + + double yMin = vlGraph.getY(); + double yMax = vlGraph.getY() + vlGraph.getInnerHeight(layoutParam.getVerticalSpaceBus()); + + // Calculate the snakeline as an horizontal layout + polyline = AbstractLayout.calculatePolylineSnakeLineForHorizontalLayout(graph, layoutParam, node1, node2, increment, infosNbSnakeLinesH, yMin, yMax); + + // Update the vertical layout maps + Integer updatedNbLinesBottom = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(BOTTOM); + Integer updatedNbLinesTop = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(TOP); + Integer updatedNbLinesLeft = infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().get(graphId); + infosNbSnakeLines.setNbSnakeLinesTopBottom(graphId, BOTTOM, updatedNbLinesBottom); + infosNbSnakeLines.setNbSnakeLinesTopBottom(graphId, TOP, updatedNbLinesTop); + infosNbSnakeLines.getNbSnakeLinesLeftRight().put(Side.LEFT, updatedNbLinesLeft); + } else { + polyline = new ArrayList<>(); + polyline.add(graph.getShiftedPoint(node1)); + layout.addMiddlePoints(layoutParam, node1, node2, increment, polyline); + polyline.add(graph.getShiftedPoint(node2)); + } + return polyline; + } +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalSubstationLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalSubstationLayout.java index 0504839bf..3419bec80 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalSubstationLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalSubstationLayout.java @@ -12,7 +12,6 @@ import com.powsybl.sld.model.nodes.Node; import com.powsybl.sld.model.coordinate.Direction; -import java.util.ArrayList; import java.util.List; import static com.powsybl.sld.model.coordinate.Direction.*; @@ -20,7 +19,7 @@ /** * @author Franck Lecuyer */ -public class VerticalSubstationLayout extends AbstractSubstationLayout { +public class VerticalSubstationLayout extends AbstractSubstationLayout implements VerticalLayout { private final InfosNbSnakeLinesVertical infosNbSnakeLines; private double maxVoltageLevelWidth; @@ -107,47 +106,14 @@ private double getHeightHorizontalSnakeLines(String vlGraphId, Direction directi @Override protected List calculatePolylineSnakeLine(LayoutParameters layoutParam, Node node1, Node node2, boolean increment) { - List polyline; - if (getGraph().getVoltageLevelGraph(node1) == getGraph().getVoltageLevelGraph(node2)) { // in the same VL (so far always horizontal layout) - VoltageLevelGraph vlGraph = getGraph().getVoltageLevelGraph(node1); - String graphId = vlGraph.getId(); - - InfosNbSnakeLinesHorizontal infosNbSnakeLinesH = InfosNbSnakeLinesHorizontal.create(vlGraph); - - // Reset the horizontal layout numbers to current graph numbers - int currentNbBottom = infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(graphId, BOTTOM); - int currentNbTop = infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(graphId, TOP); - int currentNbLeft = infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.LEFT); - infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(BOTTOM, currentNbBottom); - infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(TOP, currentNbTop); - infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().put(graphId, currentNbLeft); - - double yMin = vlGraph.getY(); - double yMax = vlGraph.getY() + vlGraph.getInnerHeight(layoutParam.getVerticalSpaceBus()); - - // Calculate the snakeline as an horizontal layout - polyline = calculatePolylineSnakeLineForHorizontalLayout(getGraph(), layoutParam, node1, node2, increment, infosNbSnakeLinesH, yMin, yMax); - - // Update the vertical layout maps - Integer updatedNbLinesBottom = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(BOTTOM); - Integer updatedNbLinesTop = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(TOP); - Integer updatedNbLinesLeft = infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().get(graphId); - infosNbSnakeLines.setNbSnakeLinesTopBottom(graphId, BOTTOM, updatedNbLinesBottom); - infosNbSnakeLines.setNbSnakeLinesTopBottom(graphId, TOP, updatedNbLinesTop); - infosNbSnakeLines.getNbSnakeLinesLeftRight().put(Side.LEFT, updatedNbLinesLeft); - - return polyline; - - } else { - polyline = new ArrayList<>(); - polyline.add(getGraph().getShiftedPoint(node1)); - addMiddlePoints(layoutParam, node1, node2, increment, polyline); - polyline.add(getGraph().getShiftedPoint(node2)); - return polyline; - } + return VerticalLayoutUtil.calculatePolylineSnakeLine(this, + getGraph(), infosNbSnakeLines, + layoutParam, node1, node2, + increment); } - protected void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node node2, boolean increment, List polyline) { + @Override + public void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node node2, boolean increment, List polyline) { Direction dNode1 = getNodeDirection(getGraph(), node1, 1); Direction dNode2 = getNodeDirection(getGraph(), node2, 2); @@ -156,7 +122,7 @@ protected void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node no int nbSnakeLines1 = increment ? infosNbSnakeLines.incrementAndGetNbSnakeLinesTopBottom(vl1, dNode1) : infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(vl1, dNode1); - double decal1V = VerticalLayout.getVerticalShift(layoutParam, dNode1, nbSnakeLines1); + double decal1V = VerticalLayoutUtil.getVerticalShift(layoutParam, dNode1, nbSnakeLines1); Point p1 = getGraph().getShiftedPoint(node1); Point p2 = getGraph().getShiftedPoint(node2); @@ -173,13 +139,13 @@ protected void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node no } else { String vl2 = getGraph().getVoltageLevelInfos(node2).getId(); int nbSnakeLines2 = infosNbSnakeLines.incrementAndGetNbSnakeLinesTopBottom(vl2, dNode2); - double decal2V = VerticalLayout.getVerticalShift(layoutParam, dNode2, nbSnakeLines2); + double decal2V = VerticalLayoutUtil.getVerticalShift(layoutParam, dNode2, nbSnakeLines2); - double ySnakeLine1 = VerticalLayout.getYSnakeLine(getGraph(), node1, dNode1, decal1V, layoutParam); - double ySnakeLine2 = VerticalLayout.getYSnakeLine(getGraph(), node2, dNode2, decal2V, layoutParam); + double ySnakeLine1 = VerticalLayoutUtil.getYSnakeLine(getGraph(), node1, dNode1, decal1V, layoutParam); + double ySnakeLine2 = VerticalLayoutUtil.getYSnakeLine(getGraph(), node2, dNode2, decal2V, layoutParam); - Side side = VerticalLayout.getSide(increment); - double xSnakeLine = VerticalLayout.getXSnakeLine(getGraph(), node1, side, layoutParam, infosNbSnakeLines, maxVoltageLevelWidth); + Side side = VerticalLayoutUtil.getSide(increment); + double xSnakeLine = VerticalLayoutUtil.getXSnakeLine(getGraph(), node1, side, layoutParam, infosNbSnakeLines, maxVoltageLevelWidth); polyline.addAll(Point.createPointsList(p1.getX(), ySnakeLine1, xSnakeLine, ySnakeLine1, xSnakeLine, ySnakeLine2, diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalZoneLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalZoneLayout.java index c1ce73553..150eadd10 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalZoneLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/VerticalZoneLayout.java @@ -15,7 +15,6 @@ import com.powsybl.sld.model.graphs.ZoneGraph; import com.powsybl.sld.model.nodes.Node; -import java.util.ArrayList; import java.util.List; import static com.powsybl.sld.model.coordinate.Direction.BOTTOM; @@ -24,7 +23,7 @@ /** * @author Thomas Adam */ -public class VerticalZoneLayout extends AbstractZoneLayout { +public class VerticalZoneLayout extends AbstractZoneLayout implements VerticalLayout { private final InfosNbSnakeLinesVertical infosNbSnakeLines; private double maxVoltageLevelWidth; @@ -71,7 +70,7 @@ public void manageSnakeLines(LayoutParameters layoutParameters) { } private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) { - VerticalLayout.adaptPaddingToSnakeLines(getGraph(), layoutParameters, infosNbSnakeLines); + VerticalLayoutUtil.adaptPaddingToSnakeLines(getGraph(), layoutParameters, infosNbSnakeLines); manageAllSnakeLines(layoutParameters); } @@ -81,47 +80,14 @@ private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) { @Override protected List calculatePolylineSnakeLine(LayoutParameters layoutParam, Node node1, Node node2, boolean increment) { - List polyline; - if (getGraph().getVoltageLevelGraph(node1) == getGraph().getVoltageLevelGraph(node2)) { // in the same VL (so far always horizontal layout) - VoltageLevelGraph vlGraph = getGraph().getVoltageLevelGraph(node1); - String graphId = vlGraph.getId(); - - InfosNbSnakeLinesHorizontal infosNbSnakeLinesH = InfosNbSnakeLinesHorizontal.create(vlGraph); - - // Reset the horizontal layout numbers to current graph numbers - int currentNbBottom = infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(graphId, BOTTOM); - int currentNbTop = infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(graphId, TOP); - int currentNbLeft = infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.LEFT); - infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(BOTTOM, currentNbBottom); - infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(TOP, currentNbTop); - infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().put(graphId, currentNbLeft); - - double yMin = vlGraph.getY(); - double yMax = vlGraph.getY() + vlGraph.getInnerHeight(layoutParam.getVerticalSpaceBus()); - - // Calculate the snakeline as an horizontal layout - polyline = calculatePolylineSnakeLineForHorizontalLayout(getGraph(), layoutParam, node1, node2, increment, infosNbSnakeLinesH, yMin, yMax); - - // Update the vertical layout maps - Integer updatedNbLinesBottom = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(BOTTOM); - Integer updatedNbLinesTop = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(TOP); - Integer updatedNbLinesLeft = infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().get(graphId); - infosNbSnakeLines.setNbSnakeLinesTopBottom(graphId, BOTTOM, updatedNbLinesBottom); - infosNbSnakeLines.setNbSnakeLinesTopBottom(graphId, TOP, updatedNbLinesTop); - infosNbSnakeLines.getNbSnakeLinesLeftRight().put(Side.LEFT, updatedNbLinesLeft); - - return polyline; - - } else { - polyline = new ArrayList<>(); - polyline.add(getGraph().getShiftedPoint(node1)); - addMiddlePoints(layoutParam, node1, node2, increment, polyline); - polyline.add(getGraph().getShiftedPoint(node2)); - return polyline; - } + return VerticalLayoutUtil.calculatePolylineSnakeLine(this, + getGraph(), infosNbSnakeLines, + layoutParam, node1, node2, + increment); } - protected void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node node2, boolean increment, List polyline) { + @Override + public void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node node2, boolean increment, List polyline) { Direction dNode1 = getNodeDirection(getGraph(), node1, 1); Direction dNode2 = getNodeDirection(getGraph(), node2, 2); @@ -130,7 +96,7 @@ protected void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node no int nbSnakeLines1 = increment ? infosNbSnakeLines.incrementAndGetNbSnakeLinesTopBottom(vl1, dNode1) : infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(vl1, dNode1); - double decal1V = VerticalLayout.getVerticalShift(layoutParam, dNode1, nbSnakeLines1); + double decal1V = VerticalLayoutUtil.getVerticalShift(layoutParam, dNode1, nbSnakeLines1); Point p1 = getGraph().getShiftedPoint(node1); Point p2 = getGraph().getShiftedPoint(node2); @@ -147,13 +113,13 @@ protected void addMiddlePoints(LayoutParameters layoutParam, Node node1, Node no } else { String vl2 = getGraph().getVoltageLevelInfos(node2).getId(); int nbSnakeLines2 = infosNbSnakeLines.incrementAndGetNbSnakeLinesTopBottom(vl2, dNode2); - double decal2V = VerticalLayout.getVerticalShift(layoutParam, dNode2, nbSnakeLines2); + double decal2V = VerticalLayoutUtil.getVerticalShift(layoutParam, dNode2, nbSnakeLines2); - double ySnakeLine1 = VerticalLayout.getYSnakeLine(getGraph(), node1, dNode1, decal1V, layoutParam); - double ySnakeLine2 = VerticalLayout.getYSnakeLine(getGraph(), node2, dNode2, decal2V, layoutParam); + double ySnakeLine1 = VerticalLayoutUtil.getYSnakeLine(getGraph(), node1, dNode1, decal1V, layoutParam); + double ySnakeLine2 = VerticalLayoutUtil.getYSnakeLine(getGraph(), node2, dNode2, decal2V, layoutParam); - Side side = VerticalLayout.getSide(increment); - double xSnakeLine = VerticalLayout.getXSnakeLine(getGraph(), node1, side, layoutParam, infosNbSnakeLines, maxVoltageLevelWidth); + Side side = VerticalLayoutUtil.getSide(increment); + double xSnakeLine = VerticalLayoutUtil.getXSnakeLine(getGraph(), node1, side, layoutParam, infosNbSnakeLines, maxVoltageLevelWidth); polyline.addAll(Point.createPointsList(p1.getX(), ySnakeLine1, xSnakeLine, ySnakeLine1, xSnakeLine, ySnakeLine2,