Skip to content

Commit

Permalink
Display Substation with Snakelines draw from Substation Layout
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <[email protected]>
  • Loading branch information
tadam50 committed Sep 28, 2023
1 parent fcd1e75 commit 8dee2ed
Show file tree
Hide file tree
Showing 8 changed files with 574 additions and 550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import com.powsybl.sld.model.graphs.ZoneGraph;

import java.util.Objects;
import java.util.*;

/**
* @author Thomas Adam <tadam at silicom.fr>
*/
public abstract class AbstractZoneLayout extends AbstractBaseLayout<ZoneGraph> {
protected SubstationLayoutFactory sLayoutFactory;
protected VoltageLevelLayoutFactory vLayoutFactory;
protected Map<SubstationGraph, AbstractLayout<SubstationGraph>> 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<SubstationGraph>) sLayout);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,41 @@ protected MatrixZoneLayout(ZoneGraph graph, String[][] matrix, SubstationLayoutF
@Override
protected void calculateCoordSubstations(LayoutParameters layoutParameters) {
// Height by rows
List<Double> maxHeightByRow = new ArrayList<>();
double maxHeightRow = 0.0;
// Width by col
List<Double> maxWidthByCol = new ArrayList<>();
double maxWidthCol = 0.0;

for (String[] strings : matrix) {
double rowHeight = 0;
double colWidth = 0;
for (String id : strings) {
Optional<SubstationGraph> 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<SubstationGraph> 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);
Expand All @@ -83,18 +76,42 @@ protected void calculateCoordSubstations(LayoutParameters layoutParameters) {
@Override
protected List<Point> calculatePolylineSnakeLine(LayoutParameters layoutParam, Pair<Node, Node> nodes,
boolean increment) {
// FIXME: need to be implemented
List<Point> polyline;
Node node1 = nodes.getFirst();
Node node2 = nodes.getSecond();
List<Point> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -59,6 +58,11 @@ public List<SubstationGraph> getSubstations() {
return substations;
}

public Optional<SubstationGraph> 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);
Expand All @@ -72,7 +76,7 @@ public Stream<VoltageLevelGraph> getVoltageLevelStream() {

@Override
public List<VoltageLevelGraph> getVoltageLevels() {
return getVoltageLevelStream().collect(Collectors.toList());
return getVoltageLevelStream().toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Loading

0 comments on commit 8dee2ed

Please sign in to comment.