Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Move circle parameters from SvgWriter to SvgParameters (#44)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup authored Jan 19, 2022
1 parent 9824260 commit 59fc39e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/powsybl/nad/svg/SvgParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class SvgParameters {
private double arrowShift = 0.3;
private double arrowLabelShift = 0.12;
private double converterStationWidth = 0.6;
private double voltageLevelCircleRadius = 0.6;
private double transformerCircleRadius = 0.2;

public enum CssLocation {
INSERTED_IN_SVG, EXTERNAL_IMPORTED, EXTERNAL_NO_IMPORT
Expand Down Expand Up @@ -124,4 +126,21 @@ public SvgParameters setConverterStationWidth(double converterStationWidth) {
return this;
}

public double getVoltageLevelCircleRadius() {
return voltageLevelCircleRadius;
}

public SvgParameters setVoltageLevelCircleRadius(double voltageLevelCircleRadius) {
this.voltageLevelCircleRadius = voltageLevelCircleRadius;
return this;
}

public double getTransformerCircleRadius() {
return transformerCircleRadius;
}

public SvgParameters setTransformerCircleRadius(double transformerCircleRadius) {
this.transformerCircleRadius = transformerCircleRadius;
return this;
}
}
17 changes: 8 additions & 9 deletions src/main/java/com/powsybl/nad/svg/SvgWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class SvgWriter {
private static final String PATH_D_ATTRIBUTE = "d";
private static final String X_ATTRIBUTE = "x";
private static final String Y_ATTRIBUTE = "y";
private static final double CIRCLE_RADIUS = 0.6;
private static final double TRANSFORMER_CIRCLE_RADIUS = 0.2;
private static final String POINTS_ATTRIBUTE = "points";

private final SvgParameters svgParameters;
Expand Down Expand Up @@ -204,7 +202,7 @@ private void drawThreeWtNodes(Graph graph, XMLStreamWriter writer) throws XMLStr
return;
}

double dNodeCenter = TRANSFORMER_CIRCLE_RADIUS * 0.6;
double dNodeCenter = svgParameters.getTransformerCircleRadius() * 0.6;
Point point1 = Point.createPointFromRhoTheta(dNodeCenter, 90);
Point point2 = Point.createPointFromRhoTheta(dNodeCenter, 210);
Point point3 = Point.createPointFromRhoTheta(dNodeCenter, 330);
Expand Down Expand Up @@ -239,7 +237,7 @@ private void draw3WtWinding(Point circleCenter, String style, XMLStreamWriter wr
}
writer.writeAttribute("cx", getFormattedValue(circleCenter.getX()));
writer.writeAttribute("cy", getFormattedValue(circleCenter.getY()));
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(TRANSFORMER_CIRCLE_RADIUS));
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(svgParameters.getTransformerCircleRadius()));
}

private void drawEdgeInfo(XMLStreamWriter writer, List<Point> line, List<EdgeInfo> edgeInfos) throws XMLStreamException {
Expand Down Expand Up @@ -294,7 +292,7 @@ private Point getArrowCenter(List<Point> line) {
if (line.size() > 2) {
return line.get(1).atDistance(svgParameters.getArrowShift(), line.get(2));
} else {
return line.get(0).atDistance(svgParameters.getArrowShift() + CIRCLE_RADIUS, line.get(1));
return line.get(0).atDistance(svgParameters.getArrowShift() + svgParameters.getVoltageLevelCircleRadius(), line.get(1));
}
}

Expand All @@ -308,10 +306,11 @@ private void draw2WtWinding(XMLStreamWriter writer, List<Point> half) throws XML
writer.writeEmptyElement(CIRCLE_ELEMENT_NAME);
Point point1 = half.get(half.size() - 1); // point in the middle
Point point2 = half.get(half.size() - 2); // point before
Point circleCenter = point1.atDistance(TRANSFORMER_CIRCLE_RADIUS / 2, point2);
double radius = svgParameters.getTransformerCircleRadius();
Point circleCenter = point1.atDistance(radius / 2, point2);
writer.writeAttribute("cx", getFormattedValue(circleCenter.getX()));
writer.writeAttribute("cy", getFormattedValue(circleCenter.getY()));
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(TRANSFORMER_CIRCLE_RADIUS));
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(radius));
}

private void drawVoltageLevelNodes(Graph graph, XMLStreamWriter writer) throws XMLStreamException {
Expand Down Expand Up @@ -365,7 +364,7 @@ private void drawNodeCircle(XMLStreamWriter writer, VoltageLevelNode vlNode) thr
writer.writeAttribute(ID_ATTRIBUTE, vlNode.getDiagramId());
addStylesIfAny(writer, styleProvider.getNodeStyleClasses(vlNode));
insertName(writer, vlNode::getName);
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(CIRCLE_RADIUS));
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(svgParameters.getVoltageLevelCircleRadius()));
}

private void writeNbBuses(XMLStreamWriter writer, VoltageLevelNode vlNode) throws XMLStreamException {
Expand Down Expand Up @@ -413,7 +412,7 @@ private void addStylesIfAny(XMLStreamWriter writer, List<String> edgeStyleClasse
}

private void shiftEdgeStart(List<Point> points) {
Point point0 = points.get(0).atDistance(CIRCLE_RADIUS, points.get(1));
Point point0 = points.get(0).atDistance(svgParameters.getVoltageLevelCircleRadius(), points.get(1));
points.get(0).setX(point0.getX());
points.get(0).setY(point0.getY());
}
Expand Down

0 comments on commit 59fc39e

Please sign in to comment.