Skip to content

Commit

Permalink
Add default matrix behaviour
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <[email protected]>
  • Loading branch information
tadam50 committed Sep 27, 2023
1 parent bb72743 commit fcd1e75
Show file tree
Hide file tree
Showing 4 changed files with 1,133 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ protected MatrixZoneLayout(ZoneGraph graph, String[][] matrix, SubstationLayoutF
@Override
protected void calculateCoordSubstations(LayoutParameters layoutParameters) {
// Height by rows
List<Double> rowsHeight = new ArrayList<>();
List<Double> maxHeightByRow = new ArrayList<>();
// Width by col
List<Double> colsWidth = new ArrayList<>();
List<Double> maxWidthByCol = new ArrayList<>();

for (String[] strings : matrix) {
double rowHeight = 0;
Expand All @@ -50,9 +50,9 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) {
rowHeight = Math.max(rowHeight, graph.getHeight());
colWidth = Math.max(colWidth, graph.getWidth());
}
colsWidth.add(colWidth);
maxWidthByCol.add(colWidth);
}
rowsHeight.add(rowHeight);
maxHeightByRow.add(rowHeight);
}

double zoneWidth = 0.0;
Expand All @@ -63,18 +63,17 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) {
double maxColWidth = 0.0;
for (int col = 0; col < matrix[row].length; col++) {
String id = matrix[row][col];

double dx = maxWidthByCol.get(col);
Optional<SubstationGraph> subGraph = getGraph().getSubstations().stream().filter(s -> s.getSubstationId().equals(id)).findFirst();
if (subGraph.isPresent()) {
SubstationGraph graph = subGraph.get();
double dx = colsWidth.get(col);
move(graph, col * dx, row * dy);
}
maxColWidth += colsWidth.get(col);
maxColWidth += dx;
}
dy = rowsHeight.get(row);
dy = maxHeightByRow.get(row);
zoneWidth = Math.max(maxColWidth, zoneWidth);
zoneHeight += rowsHeight.get(row);
zoneHeight += dy;
}

getGraph().setSize(zoneWidth, zoneHeight);
Expand All @@ -97,44 +96,5 @@ protected List<Point> calculatePolylineSnakeLine(LayoutParameters layoutParam, P
public void manageSnakeLines(LayoutParameters layoutParameters) {
// Draw snakelines for each Substations
getGraph().getSubstations().forEach(g -> manageSnakeLines(g, layoutParameters));
// Draw snakelines between all Substations
//manageSnakeLines(getGraph(), layoutParameters);
/*
// Change Voltagelevels coordinates in function of snakelines drawn
adaptPaddingToSnakeLines(layoutParameters);
// Redraw all snakelines
getGraph().getSubstations().forEach(g -> manageSnakeLines(g, layoutParameters));
manageSnakeLines(getGraph(), layoutParameters);
*/
}
/*
private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) {
double widthSnakeLinesLeft = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.LEFT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding();
LayoutParameters.Padding diagramPadding = layoutParameters.getDiagramPadding();
LayoutParameters.Padding voltageLevelPadding = layoutParameters.getVoltageLevelPadding();
double y = diagramPadding.getTop()
+ getGraph().getVoltageLevelStream().findFirst().map(vlg -> getHeightHorizontalSnakeLines(vlg.getId(), TOP, layoutParameters)).orElse(0.);
for (SubstationGraph subGraph : getGraph().getSubstations()) {
move(subGraph, widthSnakeLinesLeft, y + voltageLevelPadding.getTop());
}
for (VoltageLevelGraph vlGraph : getGraph().getVoltageLevels()) {
y += vlGraph.getHeight() + getHeightHorizontalSnakeLines(vlGraph.getId(), BOTTOM, layoutParameters);
}
double widthSnakeLinesRight = Math.max(infosNbSnakeLines.getNbSnakeLinesLeftRight().get(Side.RIGHT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding();
double substationWidth = getGraph().getWidth() + widthSnakeLinesLeft + widthSnakeLinesRight;
double substationHeight = y - diagramPadding.getTop();
getGraph().setSize(substationWidth, substationHeight);
infosNbSnakeLines.reset();
}
private double getHeightHorizontalSnakeLines(String vlGraphId, Direction direction, LayoutParameters layoutParameters) {
return Math.max(infosNbSnakeLines.getNbSnakeLinesHorizontalBetween(vlGraphId, direction) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding();
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@

import com.powsybl.sld.model.graphs.*;

import java.util.*;

/**
* @author Thomas Adam <tadam at silicom.fr>
*/
public class MatrixZoneLayoutFactory/* implements ZoneLayoutFactory*/ {
public class MatrixZoneLayoutFactory implements ZoneLayoutFactory {

// FIXME : ZoneLayoutFactory need to be refactored
//@Override
public Layout create(ZoneGraph graph, String[][] matrix, SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vLayoutFactory) {
return new MatrixZoneLayout(graph, matrix, sLayoutFactory, vLayoutFactory);
}

@Override
public Layout create(ZoneGraph graph, SubstationLayoutFactory sLayoutFactory, VoltageLevelLayoutFactory vLayoutFactory) {
// By default work as Horizontal layout
List<String> substations = graph.getSubstations().stream().map(SubstationGraph::getId).toList();
String[] array = new String[substations.size()];
String[][] matrix = new String[1][];
matrix[0] = substations.toArray(array);
return new MatrixZoneLayout(graph, matrix, sLayoutFactory, vLayoutFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,26 @@ void testZoneGraphMatrix2rows3cols() {

layoutParameters.setDiagrammPadding(1.0, 1.0, 1.0, 1.0);

// Run vertical zone layout
// Run matrix zone layout
String[][] substationsIds = {{"A", "B", "C"},
{"D", "", "E"}};
new MatrixZoneLayoutFactory().create(g, substationsIds, new VerticalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory()).run(layoutParameters);

assertEquals(toString("/TestCase13ZoneGraphMatrix2x3.svg"), toSVG(g, "/TestCase13ZoneGraphMatrix2x3.svg"));
}

@Test
void testZoneGraphMatrix1row5cols() {
// build zone graph
network = Networks.createNetworkWithManySubstations();
List<String> zone = Arrays.asList("A", "B", "C", "D", "E");
ZoneGraph g = new NetworkGraphBuilder(network).buildZoneGraph(zone);

layoutParameters.setDiagrammPadding(1.0, 1.0, 1.0, 1.0);

// Run default matrix zone layout
new MatrixZoneLayoutFactory().create(g, new VerticalSubstationLayoutFactory(), new PositionVoltageLevelLayoutFactory()).run(layoutParameters);

assertEquals(toString("/TestCase13ZoneGraphMatrix1x5.svg"), toSVG(g, "/TestCase13ZoneGraphMatrix1x5.svg"));
}
}
Loading

0 comments on commit fcd1e75

Please sign in to comment.