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

Up to N FeederInfos #341

Merged
merged 7 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
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 @@ -45,8 +45,8 @@ public class LayoutParameters {

private double horizontalSnakeLinePadding = 20;
private double verticalSnakeLinePadding = 25;
private double arrowDistance = 20;
private double minSpaceForFeederArrows = 50;
private double feederInfosOuterMargin = 20;
private double spaceForFeederInfos = 50;

private boolean avoidSVGComponentsDuplication = false;

Expand All @@ -64,7 +64,7 @@ public class LayoutParameters {

private boolean addNodesInfos = false;

private boolean feederArrowSymmetry = false;
private boolean feederInfoSymmetry = false;

private CssLocation cssLocation = CssLocation.INSERTED_IN_SVG;

Expand All @@ -76,6 +76,8 @@ public class LayoutParameters {

private boolean useName = false;

private double feederInfosIntraMargin = 10;

@JsonIgnore
private Map<String, ComponentSize> componentsSize;

Expand All @@ -99,8 +101,8 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve
@JsonProperty("drawStraightWires") boolean drawStraightWires,
@JsonProperty("horizontalSnakeLinePadding") double horizontalSnakeLinePadding,
@JsonProperty("verticalSnakeLinePadding") double verticalSnakeLinePadding,
@JsonProperty("arrowDistance") double arrowDistance,
@JsonProperty("minSpaceForFeederArrows") double minSpaceForFeederArrows,
@JsonProperty("feederInfosOuterMargin") double feederInfosOuterMargin,
@JsonProperty("spaceForFeederInfos") double spaceForFeederInfos,
@JsonProperty("diagramName") String diagramName,
@JsonProperty("avoidSVGComponentsDuplication") boolean avoidSVGComponentsDuplication,
@JsonProperty("adaptCellHeightToContent") boolean adaptCellHeightToContent,
Expand All @@ -112,10 +114,11 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve
@JsonProperty("angleLabelShift") double angleLabelShift,
@JsonProperty("highlightLineState") boolean highlightLineState,
@JsonProperty("addNodesInfos") boolean addNodesInfos,
@JsonProperty("feederArrowSymmetry") boolean feederArrowSymmetry,
@JsonProperty("feederInfoSymmetry") boolean feederInfoSymmetry,
@JsonProperty("cssLocation") CssLocation cssLocation,
@JsonProperty("svgWidthAndHeightAdded") boolean svgWidthAndHeightAdded,
@JsonProperty("useName") boolean useName) {
@JsonProperty("useName") boolean useName,
@JsonProperty("feederInfosIntraMargin") double feederInfosIntraMargin) {
this.diagramPadding = diagramPadding;
this.voltageLevelPadding = voltageLevelPadding;
this.verticalSpaceBus = verticalSpaceBus;
Expand All @@ -131,8 +134,8 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve
this.drawStraightWires = drawStraightWires;
this.horizontalSnakeLinePadding = horizontalSnakeLinePadding;
this.verticalSnakeLinePadding = verticalSnakeLinePadding;
this.arrowDistance = arrowDistance;
this.minSpaceForFeederArrows = minSpaceForFeederArrows;
this.feederInfosOuterMargin = feederInfosOuterMargin;
this.spaceForFeederInfos = spaceForFeederInfos;
this.diagramName = diagramName;
this.avoidSVGComponentsDuplication = avoidSVGComponentsDuplication;
this.adaptCellHeightToContent = adaptCellHeightToContent;
Expand All @@ -144,10 +147,11 @@ public LayoutParameters(@JsonProperty("voltageLevelPadding") Padding voltageLeve
this.angleLabelShift = angleLabelShift;
this.highlightLineState = highlightLineState;
this.addNodesInfos = addNodesInfos;
this.feederArrowSymmetry = feederArrowSymmetry;
this.feederInfoSymmetry = feederInfoSymmetry;
this.cssLocation = cssLocation;
this.svgWidthAndHeightAdded = svgWidthAndHeightAdded;
this.useName = useName;
this.feederInfosIntraMargin = feederInfosIntraMargin;
}

public LayoutParameters(LayoutParameters other) {
Expand All @@ -167,8 +171,8 @@ public LayoutParameters(LayoutParameters other) {
drawStraightWires = other.drawStraightWires;
horizontalSnakeLinePadding = other.horizontalSnakeLinePadding;
verticalSnakeLinePadding = other.verticalSnakeLinePadding;
arrowDistance = other.arrowDistance;
minSpaceForFeederArrows = other.minSpaceForFeederArrows;
feederInfosOuterMargin = other.feederInfosOuterMargin;
spaceForFeederInfos = other.spaceForFeederInfos;
diagramName = other.diagramName;
avoidSVGComponentsDuplication = other.avoidSVGComponentsDuplication;
adaptCellHeightToContent = other.adaptCellHeightToContent;
Expand All @@ -181,10 +185,11 @@ public LayoutParameters(LayoutParameters other) {
labelCentered = other.labelCentered;
highlightLineState = other.highlightLineState;
addNodesInfos = other.addNodesInfos;
feederArrowSymmetry = other.feederArrowSymmetry;
feederInfoSymmetry = other.feederInfoSymmetry;
cssLocation = other.cssLocation;
svgWidthAndHeightAdded = other.svgWidthAndHeightAdded;
useName = other.useName;
feederInfosIntraMargin = other.feederInfosIntraMargin;
}

public double getVerticalSpaceBus() {
Expand Down Expand Up @@ -304,12 +309,12 @@ public LayoutParameters setVerticalSnakeLinePadding(double verticalSnakeLinePadd
return this;
}

public double getArrowDistance() {
return arrowDistance;
public double getFeederInfosOuterMargin() {
return feederInfosOuterMargin;
}

public LayoutParameters setArrowDistance(double arrowDistance) {
this.arrowDistance = arrowDistance;
public LayoutParameters setFeederInfosOuterMargin(double feederInfosOuterMargin) {
this.feederInfosOuterMargin = feederInfosOuterMargin;
return this;
}

Expand Down Expand Up @@ -420,21 +425,21 @@ public LayoutParameters setAddNodesInfos(boolean addNodesInfos) {
return this;
}

public double getMinSpaceForFeederArrows() {
return minSpaceForFeederArrows;
public double getSpaceForFeederInfos() {
return spaceForFeederInfos;
}

public LayoutParameters setMinSpaceForFeederArrows(double minSpaceForFeederArrows) {
this.minSpaceForFeederArrows = minSpaceForFeederArrows;
public LayoutParameters setSpaceForFeederInfos(double spaceForFeederInfos) {
this.spaceForFeederInfos = spaceForFeederInfos;
return this;
}

public boolean isFeederArrowSymmetry() {
return feederArrowSymmetry;
public boolean isFeederInfoSymmetry() {
return feederInfoSymmetry;
}

public LayoutParameters setFeederArrowSymmetry(boolean feederArrowSymmetry) {
this.feederArrowSymmetry = feederArrowSymmetry;
public LayoutParameters setFeederInfoSymmetry(boolean feederInfoSymmetry) {
this.feederInfoSymmetry = feederInfoSymmetry;
return this;
}

Expand Down Expand Up @@ -488,6 +493,15 @@ public LayoutParameters setUseName(boolean useName) {
return this;
}

public double getFeederInfosIntraMargin() {
return feederInfosIntraMargin;
}

public LayoutParameters setFeederInfosIntraMargin(double feederInfosIntraMargin) {
this.feederInfosIntraMargin = feederInfosIntraMargin;
return this;
}

public enum CssLocation {
INSERTED_IN_SVG, EXTERNAL_IMPORTED, EXTERNAL_NO_IMPORT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ private void calculateExternCellHeight(LayoutParameters layoutParam) {
public static double getFeederSpan(LayoutParameters layoutParam) {
// The space needed between the feeder and the node connected to it corresponds to the space for feeder arrows
// + half the height of the feeder component + half the height of that node component
return layoutParam.getMinSpaceForFeederArrows() + layoutParam.getMaxComponentHeight();
return layoutParam.getSpaceForFeederInfos() + layoutParam.getMaxComponentHeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<FeederInfo> getFeederInfos(FeederNode node) {
default:
break;
}
if (node.getDirection() == BusCell.Direction.BOTTOM && !layoutParameters.isFeederArrowSymmetry()) {
if (node.getDirection() == BusCell.Direction.BOTTOM && !layoutParameters.isFeederInfoSymmetry()) {
Collections.reverse(feederInfos);
}
return feederInfos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,17 @@ protected void insertComponentSVGIntoDocumentSVG(String prefixId,
insertSVGIntoDocumentSVG(node.getName(), componentType, g, elementAttributesSetter);
}

protected void insertArrowSVGIntoDocumentSVG(String arrowType, String prefixId, Element g, double angle) {
protected void insertFeederInfoSVGIntoDocumentSVG(String feederInfoType, String prefixId, Element g, double angle) {
BiConsumer<Element, String> elementAttributesSetter
= (e, subComponent) -> setArrowAttributes(arrowType, prefixId, g, e, subComponent, angle);
insertSVGIntoDocumentSVG("", arrowType, g, elementAttributesSetter);
= (e, subComponent) -> setFeederInfoAttributes(feederInfoType, prefixId, g, e, subComponent, angle);
insertSVGIntoDocumentSVG("", feederInfoType, g, elementAttributesSetter);
}

private void setArrowAttributes(String arrowType, String prefixId, Element g, Element e, String subComponent, double angle) {
private void setFeederInfoAttributes(String feederInfoType, String prefixId, Element g, Element e, String subComponent, double angle) {
replaceId(g, e, prefixId);
componentLibrary.getSubComponentStyleClass(arrowType, subComponent).ifPresent(style -> e.setAttribute(CLASS, style));
componentLibrary.getSubComponentStyleClass(feederInfoType, subComponent).ifPresent(style -> e.setAttribute(CLASS, style));
if (Math.abs(angle) > 0) {
ComponentSize componentSize = componentLibrary.getSize(arrowType);
ComponentSize componentSize = componentLibrary.getSize(feederInfoType);
double cx = componentSize.getWidth() / 2;
double cy = componentSize.getHeight() / 2;
e.setAttribute(TRANSFORM, ROTATE + "(" + angle + "," + cx + "," + cy + ")");
Expand Down Expand Up @@ -761,13 +761,13 @@ private double[] getNodeTranslate(Node node) {
return new double[]{translateX, translateY};
}

protected void transformArrow(List<Point> points, ComponentSize componentSize, double shift, Element g) {
protected void transformFeederInfo(List<Point> points, ComponentSize componentSize, double shift, Element g) {
Point pointA = points.get(0);
Point pointB = points.get(1);
double distancePoints = pointA.distance(pointB);

// Case of wires with non-direct straight lines: if wire distance between first 2 points is too small to display
// the arrow, checks if the distance between the 2nd and the 3rd points is big enough
// the feeder info, checks if the distance between the 2nd and the 3rd points is big enough
if (points.size() > 2 && distancePoints < 3 * componentSize.getHeight()) {
double distancePoints23 = points.get(1).distance(points.get(2));
if (distancePoints23 > 3 * componentSize.getHeight()) {
Expand All @@ -785,20 +785,14 @@ protected void transformArrow(List<Point> points, ComponentSize componentSize, d
double cosAngle = dx / distancePoints;
double sinAngle = dy / distancePoints;

// If not enough space to have layoutParameters.getArrowDistance() at both sides of the 2 arrows,
// we compute the distance between feeder anchor and first arrow so that the two arrows are centered.
double distFeederAnchorToFirstArrowCenter =
distancePoints >= 2 * layoutParameters.getArrowDistance() + 2 * componentSize.getHeight()
? layoutParameters.getArrowDistance()
: (distancePoints - 2 * componentSize.getHeight()) / 2;
double x = pointA.getX() + cosAngle * (distFeederAnchorToFirstArrowCenter + shift);
double y = pointA.getY() + sinAngle * (distFeederAnchorToFirstArrowCenter + shift);

double arrowRotationAngle = Math.atan(dy / dx) - Math.PI / 2;
if (arrowRotationAngle < -Math.PI / 2) {
arrowRotationAngle += Math.PI;
double x = pointA.getX() + cosAngle * (layoutParameters.getFeederInfosOuterMargin() + shift);
double y = pointA.getY() + sinAngle * (layoutParameters.getFeederInfosOuterMargin() + shift);

double feederInfoRotationAngle = Math.atan(dy / dx) - Math.PI / 2;
if (feederInfoRotationAngle < -Math.PI / 2) {
feederInfoRotationAngle += Math.PI;
}
g.setAttribute(TRANSFORM, getTransformString(x, y, arrowRotationAngle, componentSize));
g.setAttribute(TRANSFORM, getTransformString(x, y, feederInfoRotationAngle, componentSize));
}

}
Expand Down Expand Up @@ -851,15 +845,15 @@ protected void insertFeederInfos(String prefixId,
points.add(new Point(feederNode.getDiagramCoordinates()));
}

int iArrow = 0;
double shiftFeederInfo = 0;
for (FeederInfo feederInfo : initProvider.getFeederInfos(feederNode)) {
// Compute shifting even if not displayed to ensure aligned arrows
double height = componentLibrary.getSize(feederInfo.getComponentType()).getHeight();
double shiftArrow = iArrow++ * 2 * height;
if (!feederInfo.isEmpty()) {
drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftArrow, metadata);
drawFeederInfo(prefixId, feederNode.getId(), points, root, feederInfo, shiftFeederInfo, metadata);
addFeederInfoComponentMetadata(metadata, feederInfo.getComponentType());
}
// Compute shifting even if not displayed to ensure aligned feeder info
double height = componentLibrary.getSize(feederInfo.getComponentType()).getHeight();
shiftFeederInfo += layoutParameters.getFeederInfosIntraMargin() + height;
}
}

Expand All @@ -886,17 +880,17 @@ private void drawFeederInfo(String prefixId, String feederNodeId, List<Point> po
List<String> styles = new ArrayList<>(3);
componentLibrary.getComponentStyleClass(feederInfo.getComponentType()).ifPresent(styles::add);

transformArrow(points, size, shift, g);
transformFeederInfo(points, size, shift, g);

String svgId = escapeId(feederNodeId) + "_" + feederInfo.getComponentType();
g.setAttribute("id", svgId);

metadata.addFeederInfoMetadata(new FeederInfoMetadata(svgId, feederNodeId, feederInfo.getUserDefinedId()));

// we draw the arrow only if direction is present
// we draw the feeder info only if direction is present
feederInfo.getDirection().ifPresent(direction -> {
double rotationAngle = points.get(0).getY() > points.get(1).getY() ? 180 : 0;
insertArrowSVGIntoDocumentSVG(feederInfo.getComponentType(), prefixId, g, rotationAngle);
insertFeederInfoSVGIntoDocumentSVG(feederInfo.getComponentType(), prefixId, g, rotationAngle);
styles.add(direction == Direction.OUT ? OUT_CLASS : IN_CLASS);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ private static LayoutParameters createDefaultLayoutParameters() {
.setShowGrid(true)
.setShowInternalNodes(true)
.setScaleFactor(1)
.setArrowDistance(20)
.setFeederInfosOuterMargin(20)
.setDrawStraightWires(false)
.setHorizontalSnakeLinePadding(30)
.setVerticalSnakeLinePadding(30)
.setCssLocation(LayoutParameters.CssLocation.INSERTED_IN_SVG)
.setSvgWidthAndHeightAdded(true)
.setUseName(true);
.setUseName(true)
.setFeederInfosIntraMargin(10);
}

protected ResourcesComponentLibrary getResourcesComponentLibrary() {
Expand Down
Loading