Skip to content

Commit

Permalink
Add AbstractBaseLayout in place of VerticalLayout & HorizontalLayout …
Browse files Browse the repository at this point in the history
…interfaces

Signed-off-by: Thomas ADAM <tadam@silicom.fr>
  • Loading branch information
tadam50 committed Jul 7, 2023
1 parent 65f353d commit 1b60432
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@
/**
* @author Thomas Adam <tadam at silicom.fr>
*/
public interface VerticalLayout {
public abstract class AbstractBaseLayout extends AbstractLayout {

InfosNbSnakeLinesVertical getInfosNbSnakeLines();
protected abstract InfosNbSnakeLinesHorizontal getInfosNbSnakeLinesHorizontal();

double getMaxVoltageLevelWidth();
protected abstract InfosNbSnakeLinesVertical getInfosNbSnakeLinesVertical();

boolean facingNodes(Node node1, Node node2);
protected abstract double getMaxVoltageLevelWidth();

default List<Point> calculatePolylineSnakeLine(BaseGraph graph,
LayoutParameters layoutParam, Pair<Node, Node> nodes,
boolean increment) {
protected abstract boolean facingNodes(Node node1, Node node2);

protected List<Point> calculatePolylineSnakeLine(BaseGraph graph,
LayoutParameters layoutParam,
Pair<Node, Node> nodes,
boolean increment) {
List<Point> polyline;
Node node1 = nodes.getFirst();
Node node2 = nodes.getSecond();
Expand All @@ -46,9 +49,9 @@ default List<Point> calculatePolylineSnakeLine(BaseGraph graph,
InfosNbSnakeLinesHorizontal infosNbSnakeLinesH = InfosNbSnakeLinesHorizontal.create(vlGraph);

// Reset the horizontal layout numbers to current graph numbers
int currentNbBottom = getInfosNbSnakeLines().getNbSnakeLinesHorizontalBetween(graphId, BOTTOM);
int currentNbTop = getInfosNbSnakeLines().getNbSnakeLinesHorizontalBetween(graphId, TOP);
int currentNbLeft = getInfosNbSnakeLines().getNbSnakeLinesLeftRight().get(Side.LEFT);
int currentNbBottom = getInfosNbSnakeLinesVertical().getNbSnakeLinesHorizontalBetween(graphId, BOTTOM);
int currentNbTop = getInfosNbSnakeLinesVertical().getNbSnakeLinesHorizontalBetween(graphId, TOP);
int currentNbLeft = getInfosNbSnakeLinesVertical().getNbSnakeLinesLeftRight().get(Side.LEFT);
infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(BOTTOM, currentNbBottom);
infosNbSnakeLinesH.getNbSnakeLinesTopBottom().put(TOP, currentNbTop);
infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().put(graphId, currentNbLeft);
Expand All @@ -63,60 +66,117 @@ default List<Point> calculatePolylineSnakeLine(BaseGraph graph,
Integer updatedNbLinesBottom = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(BOTTOM);
Integer updatedNbLinesTop = infosNbSnakeLinesH.getNbSnakeLinesTopBottom().get(TOP);
Integer updatedNbLinesLeft = infosNbSnakeLinesH.getNbSnakeLinesVerticalBetween().get(graphId);
getInfosNbSnakeLines().setNbSnakeLinesTopBottom(graphId, BOTTOM, updatedNbLinesBottom);
getInfosNbSnakeLines().setNbSnakeLinesTopBottom(graphId, TOP, updatedNbLinesTop);
getInfosNbSnakeLines().getNbSnakeLinesLeftRight().put(Side.LEFT, updatedNbLinesLeft);
getInfosNbSnakeLinesVertical().setNbSnakeLinesTopBottom(graphId, BOTTOM, updatedNbLinesBottom);
getInfosNbSnakeLinesVertical().setNbSnakeLinesTopBottom(graphId, TOP, updatedNbLinesTop);
getInfosNbSnakeLinesVertical().getNbSnakeLinesLeftRight().put(Side.LEFT, updatedNbLinesLeft);
} else {
polyline = new ArrayList<>();
polyline.add(graph.getShiftedPoint(node1));
addMiddlePoints(this, graph, layoutParam, node1, node2, increment, polyline);
addMiddlePoints(graph, layoutParam, node1, node2, increment, polyline);
polyline.add(graph.getShiftedPoint(node2));
}
return polyline;
}

default void adaptPaddingToSnakeLines(AbstractBaseGraph graph, LayoutParameters layoutParameters) {
double widthSnakeLinesLeft = Math.max(getInfosNbSnakeLines().getNbSnakeLinesLeftRight().get(Side.LEFT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding();
protected void adaptPaddingToSnakeLinesForVertical(AbstractBaseGraph graph, LayoutParameters layoutParameters) {
double widthSnakeLinesLeft = Math.max(getInfosNbSnakeLinesVertical().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, getInfosNbSnakeLines())).orElse(0.);
+ graph.getVoltageLevelStream().findFirst().map(vlg -> getHeightHorizontalSnakeLines(vlg.getId(), TOP, layoutParameters, getInfosNbSnakeLinesVertical())).orElse(0.);

for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) {
vlGraph.setCoord(xVoltageLevels, y + voltageLevelPadding.getTop());
y += vlGraph.getHeight() + getHeightHorizontalSnakeLines(vlGraph.getId(), BOTTOM, layoutParameters, getInfosNbSnakeLines());
y += vlGraph.getHeight() + getHeightHorizontalSnakeLines(vlGraph.getId(), BOTTOM, layoutParameters, getInfosNbSnakeLinesVertical());
}

double widthSnakeLinesRight = Math.max(getInfosNbSnakeLines().getNbSnakeLinesLeftRight().get(Side.RIGHT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding();
double widthSnakeLinesRight = Math.max(getInfosNbSnakeLinesVertical().getNbSnakeLinesLeftRight().get(Side.RIGHT) - 1, 0) * layoutParameters.getHorizontalSnakeLinePadding();
double substationWidth = graph.getWidth() + widthSnakeLinesLeft + widthSnakeLinesRight;
double substationHeight = y - diagramPadding.getTop();
graph.setSize(substationWidth, substationHeight);

getInfosNbSnakeLines().reset();
getInfosNbSnakeLinesVertical().reset();
}

protected void adaptPaddingToSnakeLinesForHorizontal(AbstractBaseGraph graph, LayoutParameters layoutParameters) {
double heightSnakeLinesTop = AbstractLayout.getHeightSnakeLines(layoutParameters, TOP, getInfosNbSnakeLinesHorizontal());

LayoutParameters.Padding diagramPadding = layoutParameters.getDiagramPadding();
LayoutParameters.Padding voltageLevelPadding = layoutParameters.getVoltageLevelPadding();

double topPadding = heightSnakeLinesTop + diagramPadding.getTop() + voltageLevelPadding.getTop();
double x = diagramPadding.getLeft();

for (VoltageLevelGraph vlGraph : graph.getVoltageLevels()) {
x += AbstractLayout.getWidthVerticalSnakeLines(vlGraph.getId(), layoutParameters, getInfosNbSnakeLinesHorizontal());
vlGraph.setCoord(x + voltageLevelPadding.getLeft(), computeCoordY(graph, layoutParameters, topPadding, vlGraph));
x += vlGraph.getWidth();
}

double zoneWidth = x - diagramPadding.getLeft();
double heightSnakeLinesBottom = AbstractLayout.getHeightSnakeLines(layoutParameters, BOTTOM, getInfosNbSnakeLinesHorizontal());
double zoneHeight = graph.getHeight() + heightSnakeLinesTop + heightSnakeLinesBottom;

graph.setSize(zoneWidth, zoneHeight);

getInfosNbSnakeLinesHorizontal().reset();
}

static double computeCoordY(AbstractBaseGraph graph, LayoutParameters layoutParameters, double topPadding, VoltageLevelGraph vlGraph) {
double y;
// Find maximum voltage level top height
double maxTopExternCellHeight = graph.getVoltageLevelStream().mapToDouble(g -> g.getExternCellHeight(Direction.TOP)).max().orElse(0.0);
// Get gap between current voltage level and maximum height one
double delta = maxTopExternCellHeight - vlGraph.getExternCellHeight(Direction.TOP);
// Find maximum voltage level maxV
double maxV = graph.getVoltageLevelStream().mapToDouble(VoltageLevelGraph::getMaxV).max().orElse(0.0);
// Get all busbar section height
double bbsHeight = layoutParameters.getVerticalSpaceBus() * (maxV - vlGraph.getMaxV());

switch (layoutParameters.getBusbarsAlignment()) {
case FIRST: {
// Align on First busbar section
y = topPadding + delta;
break;
}
case LAST: {
// Align on Last busbar section
y = topPadding + delta + bbsHeight;
break;
}
case MIDDLE: {
// Align on middle of all busbar section
y = topPadding + delta + bbsHeight / 2;
break;
}
case NONE: // None alignment
default:
y = topPadding;
}
return y;
}

private static void addMiddlePoints(VerticalLayout layout,
BaseGraph graph,
LayoutParameters layoutParam, Node node1, Node node2,
boolean increment,
List<Point> polyline) {
protected void addMiddlePoints(BaseGraph graph,
LayoutParameters layoutParam, Node node1, Node node2,
boolean increment,
List<Point> polyline) {
Direction dNode1 = AbstractLayout.getNodeDirection(graph, node1, 1);
Direction dNode2 = AbstractLayout.getNodeDirection(graph, node2, 2);

// increment not needed for 3WT for the common node
String vl1 = graph.getVoltageLevelInfos(node1).getId();
int nbSnakeLines1 = increment
? layout.getInfosNbSnakeLines().incrementAndGetNbSnakeLinesTopBottom(vl1, dNode1)
: layout.getInfosNbSnakeLines().getNbSnakeLinesHorizontalBetween(vl1, dNode1);
? getInfosNbSnakeLinesVertical().incrementAndGetNbSnakeLinesTopBottom(vl1, dNode1)
: getInfosNbSnakeLinesVertical().getNbSnakeLinesHorizontalBetween(vl1, dNode1);
double decal1V = getVerticalShift(layoutParam, dNode1, nbSnakeLines1);

Point p1 = graph.getShiftedPoint(node1);
Point p2 = graph.getShiftedPoint(node2);

if (layout.facingNodes(node1, node2)) {
if (facingNodes(node1, node2)) {
// if the two nodes are facing each other, no need to add more than 2 points (and one point is enough if same abscissa)
double ySnakeLine = Math.min(p1.getY(), p2.getY()) + decal1V;
if (p1.getX() != p2.getX()) {
Expand All @@ -127,14 +187,14 @@ private static void addMiddlePoints(VerticalLayout layout,
}
} else {
String vl2 = graph.getVoltageLevelInfos(node2).getId();
int nbSnakeLines2 = layout.getInfosNbSnakeLines().incrementAndGetNbSnakeLinesTopBottom(vl2, dNode2);
int nbSnakeLines2 = getInfosNbSnakeLinesVertical().incrementAndGetNbSnakeLinesTopBottom(vl2, dNode2);
double decal2V = getVerticalShift(layoutParam, dNode2, nbSnakeLines2);

double ySnakeLine1 = getYSnakeLine(graph, node1, dNode1, decal1V, layoutParam);
double ySnakeLine2 = getYSnakeLine(graph, node2, dNode2, decal2V, layoutParam);

Side side = getSide(increment);
double xSnakeLine = getXSnakeLine(graph, node1, side, layoutParam, layout.getInfosNbSnakeLines(), layout.getMaxVoltageLevelWidth());
double xSnakeLine = getXSnakeLine(graph, node1, side, layoutParam, getInfosNbSnakeLinesVertical(), getMaxVoltageLevelWidth());
polyline.addAll(Point.createPointsList(p1.getX(), ySnakeLine1,
xSnakeLine, ySnakeLine1,
xSnakeLine, ySnakeLine2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
* @author Massimo Ferraro <massimo.ferraro@techrain.eu>
*/
public abstract class AbstractSubstationLayout extends AbstractLayout {
public abstract class AbstractSubstationLayout extends AbstractBaseLayout {

private final SubstationGraph graph;
protected VoltageLevelLayoutFactory vLayoutFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author Thomas Adam <tadam at silicom.fr>
*/
public abstract class AbstractZoneLayout extends AbstractLayout {
public abstract class AbstractZoneLayout extends AbstractBaseLayout {

private final ZoneGraph graph;
protected SubstationLayoutFactory sLayoutFactory;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
public class HorizontalSubstationLayout extends AbstractSubstationLayout implements HorizontalLayout {
public class HorizontalSubstationLayout extends AbstractSubstationLayout {

private final InfosNbSnakeLinesHorizontal infosNbSnakeLines;

Expand Down Expand Up @@ -54,7 +54,7 @@ protected void calculateCoordVoltageLevels(LayoutParameters layoutParameters) {
vLayout.run(layoutParameters);

x += voltageLevelPadding.getLeft();
vlGraph.setCoord(x, HorizontalLayout.computeCoordY(getGraph(), layoutParameters, topPadding, vlGraph));
vlGraph.setCoord(x, computeCoordY(getGraph(), layoutParameters, topPadding, vlGraph));

x += vlGraph.getWidth() + voltageLevelPadding.getRight();
substationHeight = Math.max(substationHeight, vlGraph.getHeight());
Expand All @@ -73,14 +73,29 @@ public void manageSnakeLines(LayoutParameters layoutParameters) {
}

private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) {
adaptPaddingToSnakeLines(getGraph(), layoutParameters);
adaptPaddingToSnakeLinesForHorizontal(getGraph(), layoutParameters);

getGraph().getVoltageLevels().forEach(g -> manageSnakeLines(g, layoutParameters));
manageSnakeLines(getGraph(), layoutParameters);
}

@Override
public InfosNbSnakeLinesHorizontal getInfosNbSnakeLines() {
public InfosNbSnakeLinesHorizontal getInfosNbSnakeLinesHorizontal() {
return infosNbSnakeLines;
}

@Override
protected InfosNbSnakeLinesVertical getInfosNbSnakeLinesVertical() {
return null;
}

@Override
protected double getMaxVoltageLevelWidth() {
return Double.NaN;
}

@Override
protected boolean facingNodes(Node node1, Node node2) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @author Thomas Adam <tadam at silicom.fr>
*/
public class HorizontalZoneLayout extends AbstractZoneLayout implements HorizontalLayout {
public class HorizontalZoneLayout extends AbstractZoneLayout {

private final InfosNbSnakeLinesHorizontal infosNbSnakeLines;

Expand Down Expand Up @@ -69,13 +69,28 @@ public void manageSnakeLines(LayoutParameters layoutParameters) {
}

private void adaptPaddingToSnakeLines(LayoutParameters layoutParameters) {
adaptPaddingToSnakeLines(getGraph(), layoutParameters);
adaptPaddingToSnakeLinesForHorizontal(getGraph(), layoutParameters);

manageAllSnakeLines(layoutParameters);
}

@Override
public InfosNbSnakeLinesHorizontal getInfosNbSnakeLines() {
public InfosNbSnakeLinesHorizontal getInfosNbSnakeLinesHorizontal() {
return infosNbSnakeLines;
}

@Override
protected InfosNbSnakeLinesVertical getInfosNbSnakeLinesVertical() {
return null;
}

@Override
protected double getMaxVoltageLevelWidth() {
return Double.NaN;
}

@Override
protected boolean facingNodes(Node node1, Node node2) {
return false;
}
}
Loading

0 comments on commit 1b60432

Please sign in to comment.