diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/AbstractZoneLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/AbstractZoneLayout.java index 1c19225ab..6f582ead0 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/AbstractZoneLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/AbstractZoneLayout.java @@ -11,7 +11,7 @@ import com.powsybl.sld.model.graphs.VoltageLevelGraph; import com.powsybl.sld.model.graphs.ZoneGraph; -import java.util.Objects; +import java.util.*; /** * @author Thomas Adam @@ -19,11 +19,17 @@ public abstract class AbstractZoneLayout extends AbstractBaseLayout { protected SubstationLayoutFactory sLayoutFactory; protected VoltageLevelLayoutFactory vLayoutFactory; + protected Map> layoutBySubstation; protected AbstractZoneLayout(ZoneGraph graph, SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vLayoutFactory) { super(graph); this.sLayoutFactory = Objects.requireNonNull(sLayoutFactory); this.vLayoutFactory = Objects.requireNonNull(vLayoutFactory); + this.layoutBySubstation = new HashMap<>(); + for (SubstationGraph subGraph : getGraph().getSubstations()) { + Layout sLayout = sLayoutFactory.create(subGraph, vLayoutFactory); + layoutBySubstation.put(subGraph, (AbstractLayout) sLayout); + } } @Override 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 8a76b55b0..065653f3f 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 @@ -48,9 +48,7 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) { double zoneHeight = 0.0; for (SubstationGraph subGraph : getGraph().getSubstations()) { - // Calculate the objects coordinates inside the zone graph - Layout sLayout = sLayoutFactory.create(subGraph, vLayoutFactory); - sLayout.run(layoutParameters); + layoutBySubstation.get(subGraph).run(layoutParameters); move(subGraph, zoneWidth, 0); diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/MatrixZoneLayout.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/MatrixZoneLayout.java index 2281eeb6d..09e28319c 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/MatrixZoneLayout.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/MatrixZoneLayout.java @@ -32,48 +32,41 @@ protected MatrixZoneLayout(ZoneGraph graph, String[][] matrix, SubstationLayoutF @Override protected void calculateCoordSubstations(LayoutParameters layoutParameters) { // Height by rows - List maxHeightByRow = new ArrayList<>(); + double maxHeightRow = 0.0; // Width by col - List maxWidthByCol = new ArrayList<>(); + double maxWidthCol = 0.0; for (String[] strings : matrix) { - double rowHeight = 0; - double colWidth = 0; for (String id : strings) { Optional subGraph = getGraph().getSubstations().stream().filter(s -> s.getSubstationId().equals(id)).findFirst(); if (subGraph.isPresent()) { SubstationGraph graph = subGraph.get(); // Display substations - Layout sLayout = sLayoutFactory.create(graph, vLayoutFactory); - sLayout.run(layoutParameters); + layoutBySubstation.get(graph).run(layoutParameters); - rowHeight = Math.max(rowHeight, graph.getHeight()); - colWidth = Math.max(colWidth, graph.getWidth()); + maxHeightRow = Math.max(maxHeightRow, graph.getHeight()); + maxWidthCol = Math.max(maxWidthCol, graph.getWidth()); } - maxWidthByCol.add(colWidth); } - maxHeightByRow.add(rowHeight); } + LayoutParameters.Padding diagramPadding = layoutParameters.getDiagramPadding(); double zoneWidth = 0.0; double zoneHeight = 0.0; - double dy = 0.0; for (int row = 0; row < matrix.length; row++) { double maxColWidth = 0.0; for (int col = 0; col < matrix[row].length; col++) { String id = matrix[row][col]; - double dx = maxWidthByCol.get(col); Optional subGraph = getGraph().getSubstations().stream().filter(s -> s.getSubstationId().equals(id)).findFirst(); if (subGraph.isPresent()) { SubstationGraph graph = subGraph.get(); - move(graph, col * dx, row * dy); + move(graph, col * maxWidthCol + diagramPadding.getLeft(), row * maxHeightRow + diagramPadding.getTop()); } - maxColWidth += dx; + maxColWidth += maxWidthCol; } - dy = maxHeightByRow.get(row); zoneWidth = Math.max(maxColWidth, zoneWidth); - zoneHeight += dy; + zoneHeight += maxHeightRow; } getGraph().setSize(zoneWidth, zoneHeight); @@ -83,18 +76,42 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) { @Override protected List calculatePolylineSnakeLine(LayoutParameters layoutParam, Pair nodes, boolean increment) { - // FIXME: need to be implemented + List polyline; Node node1 = nodes.getFirst(); Node node2 = nodes.getSecond(); - List pol = new ArrayList<>(); - pol.add(getGraph().getShiftedPoint(node1)); - pol.add(getGraph().getShiftedPoint(node2)); - return pol; + VoltageLevelGraph vl1Graph = getGraph().getVoltageLevelGraph(node1); + VoltageLevelGraph vl2Graph = getGraph().getVoltageLevelGraph(node2); + SubstationGraph ss1Graph = getGraph().getSubstationGraph(node1).orElse(null); + SubstationGraph ss2Graph = getGraph().getSubstationGraph(node2).orElse(null); + if (vl1Graph == vl2Graph) { // in the same VL (so far always horizontal layout) + throw new UnsupportedOperationException(); + } else if (ss1Graph != null && ss1Graph == ss2Graph) { // in the same SS + polyline = layoutBySubstation.get(ss1Graph).calculatePolylineSnakeLine(layoutParam, nodes, increment); + } else { // in the same Zone + // FIXME: need to be improved + polyline = new ArrayList<>(); + //polyline.add(getGraph().getShiftedPoint(node1)); + //polyline.add(getGraph().getShiftedPoint(node2)); + } + return polyline; } @Override public void manageSnakeLines(LayoutParameters layoutParameters) { - // Draw snakelines for each Substations + // Draw snakelines between VoltageLevel for each Substations getGraph().getSubstations().forEach(g -> manageSnakeLines(g, layoutParameters)); + // Draw snakelines between Substations + manageSnakeLines(getGraph(), layoutParameters); + // Move each substation taking into account snakelines + adaptPaddingToSnakeLines(layoutParameters); + } + + private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) { + // FIXME: need to be implemented + + // Re-draw snakelines between VoltageLevel for each Substations + // getGraph().getSubstations().forEach(g -> manageSnakeLines(g, layoutParameters)); + // Re-draw snakelines between Substations + // manageSnakeLines(getGraph(), layoutParameters); } } 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 807dc88a4..2f3b4e2a0 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 @@ -71,8 +71,7 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) { for (SubstationGraph subGraph : getGraph().getSubstations()) { // Calculate the objects coordinates inside the substation graph - Layout sLayout = sLayoutFactory.create(subGraph, vLayoutFactory); - sLayout.run(layoutParameters); + layoutBySubstation.get(subGraph).run(layoutParameters); move(subGraph, 0, zoneHeight); diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/graphs/ZoneGraph.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/graphs/ZoneGraph.java index a89edca0c..abf061dfa 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/graphs/ZoneGraph.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/model/graphs/ZoneGraph.java @@ -12,7 +12,6 @@ import java.io.IOException; import java.util.*; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -59,6 +58,11 @@ public List getSubstations() { return substations; } + public Optional getSubstationGraph(Node node) { + VoltageLevelGraph vlGraph = getVoltageLevelGraph(node); + return getSubstations().stream().filter(s -> s.getVoltageLevels().contains(vlGraph)).findFirst(); + } + @Override public VoltageLevelGraph getVoltageLevel(String voltageLevelId) { Objects.requireNonNull(voltageLevelId); @@ -72,7 +76,7 @@ public Stream getVoltageLevelStream() { @Override public List getVoltageLevels() { - return getVoltageLevelStream().collect(Collectors.toList()); + return getVoltageLevelStream().toList(); } @Override 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 a08c3c5e9..9ed7d3962 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 @@ -123,7 +123,7 @@ void testZoneGraphMatrix2rows3cols() { // Run matrix zone layout String[][] substationsIds = {{"A", "B", "C"}, {"D", "", "E"}}; - new MatrixZoneLayoutFactory().create(g, substationsIds, new VerticalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory()).run(layoutParameters); + new MatrixZoneLayoutFactory().create(g, substationsIds, new HorizontalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory()).run(layoutParameters); assertEquals(toString("/TestCase13ZoneGraphMatrix2x3.svg"), toSVG(g, "/TestCase13ZoneGraphMatrix2x3.svg")); } diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix1x5.svg b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix1x5.svg index d8bcff748..368f59d56 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix1x5.svg +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix1x5.svg @@ -145,932 +145,932 @@ - A 400 + A 400 - + A 400 Bus - + - + - + - + - + - + - + - + - + A 400 230 - A 230 + A 230 - + A 230 Bus - + - + - + - + - + - + - + - + - + A 400 230 - + - + - + - + - + - + - + - + - + A - B - + - + - + - + - + - + - + - + - + AC / DC - VSC Converter1 - + - + - + - + - + - + - + - + - + A230_B230 - + - + - + - B 230 + B 230 - + B 230 Bus - + - + - + - + - + - + - + - + - + A - B - + - + - + - + - + - + - + - + - + B - C - + - + - + - + - + - + - + - + - + AC / DC - VSC Converter2 - + - + - + - + - + - + - + - + - + A230_B230 - C 230 + C 230 - + C 230 Bus - + - + - + - + - + - + - + - + - + C 230 66 - + - + - + - + - + - + - + - + - + B - C - C 66 + C 66 - + C 66 Bus - + - + - + - + - + - + - + - + - + C 230 66 - + - + - + - + - + - + - + - + - + C 66 20 - + - + - + - + - + - + - + - + - + C - D - + - + - + - + - + - + - + - + - + C66 - D - C 20 + C 20 - + C 20 Bus - + - + - + - + - + - + - + - + - + C 66 20 - + - + - + - + - + - + - D 66 + D 66 - + D 66 Bus - + - + - + - + - + - + - + - + - + D 66 10 - + - + - + - + - + - + - + - + - + C - D - + - + - + - + - + - + - + - + - + D66 - D - D 10 + D 10 - + D 10 Bus - + - + - + - + - + - + - + - + - + D 66 10 - + - + - + - + - + - + - + - + - + D - E - + - + - + - + - + - + - + - + - + H - D - + - + - + - + - + - + - + - + - + K - D - + - + - + - E 10 + E 10 - + E 10 Bus - + - + - + - + - + - + - + - + - + D - E - + - + - + - + - + - + - + - + - + E - F diff --git a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix2x3.svg b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix2x3.svg index 2531bd271..696cc130d 100644 --- a/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix2x3.svg +++ b/single-line-diagram/single-line-diagram-core/src/test/resources/TestCase13ZoneGraphMatrix2x3.svg @@ -1,5 +1,5 @@ - +