From 0e895c5f2263d4fac3e3de6ebf3f29891421ffd5 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Mon, 29 Jan 2024 10:50:53 +0100 Subject: [PATCH] Center substation into own matrix cell Signed-off-by: Thomas ADAM --- .../com/powsybl/sld/layout/MatrixZoneLayout.java | 8 +++++++- .../layout/zonebygrid/MatrixZoneLayoutModel.java | 15 ++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) 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 e3c46ead5..ef71acddf 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 @@ -57,6 +57,9 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) { // Zone size int nbRows = matrix.rowCount(); int nbCols = matrix.columnCount(); + // FIXME : padding diagram is canceled here ! + double leftPadding = layoutParameters.getDiagramPadding().getLeft(); + double topPadding = layoutParameters.getDiagramPadding().getTop(); // Move each substation into its matrix position for (int row = 0; row < nbRows; row++) { maxWidthCol = 0; @@ -64,9 +67,12 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) { MatrixCell cell = matrix.get(row, col); BaseGraph graph = cell.graph(); if (graph != null) { + // Compute delta in order to center substations into own matrix cell + int deltaX = (int)(matrix.getMatrixCellWidth(col) % graph.getWidth()) / 2; + int deltaY = (int)(matrix.getMatrixCellHeight(row) % graph.getHeight()) / 2; double dx = maxWidthCol + (col + 1.0) * snakelineMargin; double dy = maxHeightRow + (row + 1.0) * snakelineMargin; - move(graph, dx, dy); + move(graph, dx - leftPadding + deltaX, dy - topPadding + deltaY); } maxWidthCol += matrix.getMatrixCellWidth(col); } diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/zonebygrid/MatrixZoneLayoutModel.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/zonebygrid/MatrixZoneLayoutModel.java index 329fafce3..c9eeff281 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/zonebygrid/MatrixZoneLayoutModel.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/layout/zonebygrid/MatrixZoneLayoutModel.java @@ -117,18 +117,23 @@ private void computeMatrixCellsAvailability(LayoutParameters layoutParameters) { // Make empty cells available for snakeline computation List allCells = matrix.stream().toList(); allCells.forEach(cell -> { - double matrixCellWidth = matrix.getMatrixCellWidth(cell.col()); - double matrixCellHeight = matrix.getMatrixCellHeight(cell.row()); + int matrixCellWidth = (int) matrix.getMatrixCellWidth(cell.col()); + int matrixCellHeight = (int) matrix.getMatrixCellHeight(cell.row()); int ssX = getX(cell.col(), snakelineMargin); int ssY = getY(cell.row(), snakelineMargin); - + // Horizontal lines + int stepH = (int) layoutParameters.getHorizontalSnakeLinePadding(); + int deltaH = (matrixCellHeight % stepH) / 2; for (int x = ssX; x < ssX + matrixCellWidth; x++) { - for (int y = ssY; y < ssY + matrixCellHeight; y += layoutParameters.getHorizontalSnakeLinePadding()) { + for (int y = ssY + deltaH + stepH; y < ssY + matrixCellHeight - deltaH; y += stepH) { pathFinderGrid.setAvailability(x, y, true); } } - for (int x = ssX; x < ssX + matrixCellWidth; x += layoutParameters.getVerticalSnakeLinePadding()) { + // Vertical lines + int stepV = (int) layoutParameters.getVerticalSnakeLinePadding(); + int deltaV = (matrixCellWidth % stepV) / 2; + for (int x = ssX + deltaV + stepV; x < ssX + matrixCellWidth - deltaV; x += stepV) { for (int y = ssY; y < ssY + matrixCellHeight; y++) { pathFinderGrid.setAvailability(x, y, true); }