Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SLD] Fix set direction in bus cells #492

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,8 @@ public LBSCluster organizeLegBusSets(VoltageLevelGraph graph, List<LegBusSet> le
private void gatherLayoutExtensionInformation(VoltageLevelGraph graph) {

graph.getBusCellStream().forEach(bc -> {
List<Direction> listOfDirectionsInsideCell = bc.getNodes().stream().map(Node::getDirection).distinct().collect(Collectors.toList());
int numberOfDirectionsInsideCell = listOfDirectionsInsideCell.size();
if (numberOfDirectionsInsideCell == 1) {
Direction direction = listOfDirectionsInsideCell.get(0);
if (direction != Direction.UNDEFINED) {
bc.setDirection(direction);
}
} else if (numberOfDirectionsInsideCell > 1) {
bc.setDirection(listOfDirectionsInsideCell.get(numberOfDirectionsInsideCell - 1));
LOGGER.warn("Directions inside cell are not consistent: {} directions found instead of 1", numberOfDirectionsInsideCell);
}

bc.getNodes().stream().map(Node::getOrder)
.filter(Optional::isPresent)
.mapToInt(Optional::get)
.min()
.ifPresent(bc::setOrder);

if (bc.getDirection() == Direction.UNDEFINED && bc.getType() == EXTERN) {
bc.setDirection(DEFAULTDIRECTION);
}
setDirection(bc);
setOrder(bc);
});

List<ExternCell> problematicCells = graph.getExternCellStream()
Expand All @@ -154,6 +135,33 @@ private void gatherLayoutExtensionInformation(VoltageLevelGraph graph) {
}
}

private static void setDirection(BusCell bc) {
List<Direction> listOfDirectionsInsideCell = bc.getNodes().stream().map(Node::getDirection)
.filter(d -> d != Direction.UNDEFINED).distinct().collect(Collectors.toList());
int numberOfDirectionsInsideCell = listOfDirectionsInsideCell.size();
if (numberOfDirectionsInsideCell == 0) {
if (bc.getType() == EXTERN) {
bc.setDirection(DEFAULTDIRECTION);
}
// The intern cells with undefined direction cannot be forced to a default position, as they are dealt with
// later to avoid overlap, see BlockPositionner::manageInternCellOverlaps. This cannot be done now, as the
// flat intern cells haven't been yet identified
} else {
bc.setDirection(listOfDirectionsInsideCell.get(0));
if (numberOfDirectionsInsideCell > 1) {
LOGGER.warn("Directions inside cell are not consistent: {} directions found instead of 1", numberOfDirectionsInsideCell);
}
}
}

private static void setOrder(BusCell bc) {
bc.getNodes().stream().map(Node::getOrder)
.filter(Optional::isPresent)
.mapToInt(Optional::get)
.min()
.ifPresent(bc::setOrder);
}

private Comparator<LegBusSet> sortLBS = new Comparator<LegBusSet>() {
@Override
public int compare(LegBusSet lbs1, LegBusSet lbs2) {
Expand Down