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

Edge parts can be stretchable or glued #457

Merged
merged 6 commits into from
Dec 20, 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 @@ -39,6 +39,9 @@ public interface StyleProvider {
String LABEL_BOX_CLASS = CLASSES_PREFIX + "label-box";
String LEGEND_SQUARE_CLASS = CLASSES_PREFIX + "legend-square";
String PST_ARROW_CLASS = CLASSES_PREFIX + "pst-arrow";
String STRETCHABLE_CLASS = CLASSES_PREFIX + "stretchable";
String GLUED_CLASS = CLASSES_PREFIX + "glued";
String GLUED_CENTER_CLASS = CLASSES_PREFIX + "glued-center";

List<String> getCssFilenames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,41 @@ private void drawBranchEdges(Graph graph, XMLStreamWriter writer) throws XMLStre

drawHalfEdge(graph, writer, edge, BranchEdge.Side.ONE);
drawHalfEdge(graph, writer, edge, BranchEdge.Side.TWO);
if (BranchEdge.PST_EDGE.equals(edge.getType())) {
drawPstArrow(writer, edge);
}

if (edge.getType().equals(BranchEdge.HVDC_LINE_EDGE)) {
drawConverterStation(writer, edge);
}
drawEdgeCenter(writer, edge);

writer.writeEndElement();
}
writer.writeEndElement();
}

private void drawEdgeCenter(XMLStreamWriter writer, BranchEdge edge) throws XMLStreamException {
if (BranchEdge.LINE_EDGE.equals(edge.getType())) {
return;
}
writer.writeStartElement(GROUP_ELEMENT_NAME);
writer.writeAttribute(CLASS_ATTRIBUTE, StyleProvider.GLUED_CENTER_CLASS);
switch (edge.getType()) {
case BranchEdge.PST_EDGE:
case BranchEdge.TWO_WT_EDGE:
draw2Wt(writer, edge);
break;
case BranchEdge.HVDC_LINE_EDGE:
drawConverterStation(writer, edge);
break;
default:
// Should not happen as lines are discarded beforehand
}
writer.writeEndElement();
}

private void draw2Wt(XMLStreamWriter writer, BranchEdge edge) throws XMLStreamException {
draw2WtWinding(writer, edge, BranchEdge.Side.ONE);
draw2WtWinding(writer, edge, BranchEdge.Side.TWO);
if (BranchEdge.PST_EDGE.equals(edge.getType())) {
drawPstArrow(writer, edge);
}
}

private void drawConverterStation(XMLStreamWriter writer, BranchEdge edge) throws XMLStreamException {
writer.writeEmptyElement(POLYLINE_ELEMENT_NAME);
List<Point> line1 = edge.getPoints(BranchEdge.Side.ONE);
Expand Down Expand Up @@ -187,7 +209,7 @@ private void drawHalfEdge(Graph graph, XMLStreamWriter writer, BranchEdge edge,
if (edge.isVisible(side)) {
if (!graph.isLoop(edge)) {
writer.writeEmptyElement(POLYLINE_ELEMENT_NAME);
writer.writeAttribute(CLASS_ATTRIBUTE, StyleProvider.EDGE_PATH_CLASS);
writer.writeAttribute(CLASS_ATTRIBUTE, String.join(" ", StyleProvider.EDGE_PATH_CLASS, StyleProvider.STRETCHABLE_CLASS));
writer.writeAttribute(POINTS_ATTRIBUTE, getPolylinePointsString(edge, side));
drawBranchEdgeInfo(graph, writer, edge, side, labelProvider.getEdgeInfos(graph, edge, side));
} else {
Expand All @@ -197,9 +219,6 @@ private void drawHalfEdge(Graph graph, XMLStreamWriter writer, BranchEdge edge,
drawLoopEdgeInfo(writer, edge, side, labelProvider.getEdgeInfos(graph, edge, side));
}
}
if (edge.isTransformerEdge()) {
draw2WtWinding(writer, edge.getPoints(side));
}
writer.writeEndElement();
}

Expand Down Expand Up @@ -276,7 +295,8 @@ private void drawLoopEdgeInfo(XMLStreamWriter writer, BranchEdge edge, BranchEdg
private void drawBranchEdgeInfo(Graph graph, XMLStreamWriter writer, BranchEdge edge, BranchEdge.Side side, List<EdgeInfo> edgeInfos) throws XMLStreamException {
VoltageLevelNode vlNode = graph.getVoltageLevelNode(edge, side);
BusNode busNode = graph.getBusGraphNode(edge, side);
drawEdgeInfo(writer, edgeInfos, getArrowCenter(vlNode, busNode, edge.getPoints(side)), edge.getEdgeEndAngle(side));
List<String> additionalStyles = List.of(StyleProvider.GLUED_CLASS + "-" + side.getNum());
drawEdgeInfo(writer, additionalStyles, edgeInfos, getArrowCenter(vlNode, busNode, edge.getPoints(side)), edge.getEdgeEndAngle(side));
}

private void drawThreeWtEdgeInfo(Graph graph, XMLStreamWriter writer, ThreeWtEdge edge, List<EdgeInfo> edgeInfos) throws XMLStreamException {
Expand All @@ -286,8 +306,14 @@ private void drawThreeWtEdgeInfo(Graph graph, XMLStreamWriter writer, ThreeWtEdg
}

private void drawEdgeInfo(XMLStreamWriter writer, List<EdgeInfo> edgeInfos, Point infoCenter, double edgeAngle) throws XMLStreamException {
drawEdgeInfo(writer, Collections.emptyList(), edgeInfos, infoCenter, edgeAngle);
}

private void drawEdgeInfo(XMLStreamWriter writer, List<String> additionalStyles, List<EdgeInfo> edgeInfos, Point infoCenter, double edgeAngle) throws XMLStreamException {
writer.writeStartElement(GROUP_ELEMENT_NAME);
writer.writeAttribute(CLASS_ATTRIBUTE, StyleProvider.EDGE_INFOS_CLASS);
List<String> styles = new ArrayList<>(additionalStyles);
styles.add(StyleProvider.EDGE_INFOS_CLASS);
writer.writeAttribute(CLASS_ATTRIBUTE, String.join(" ", styles));
writer.writeAttribute(TRANSFORM_ATTRIBUTE, getTranslateString(infoCenter));
for (EdgeInfo info : edgeInfos) {
writer.writeStartElement(GROUP_ELEMENT_NAME);
Expand Down Expand Up @@ -396,11 +422,14 @@ private Point getArrowCenter(VoltageLevelNode vlNode, BusNode busNode, List<Poin
return line.get(line.size() - 2).atDistance(shift, line.get(line.size() - 1));
}

private void draw2WtWinding(XMLStreamWriter writer, List<Point> half) throws XMLStreamException {
private void draw2WtWinding(XMLStreamWriter writer, BranchEdge edge, BranchEdge.Side side) throws XMLStreamException {
writer.writeEmptyElement(CIRCLE_ELEMENT_NAME);
writer.writeAttribute(CLASS_ATTRIBUTE, StyleProvider.WINDING_CLASS);
Point point1 = half.get(half.size() - 1); // point near 2wt
Point point2 = half.get(half.size() - 2); // point near voltage level, or control point for loops
List<String> styles = new ArrayList<>(styleProvider.getSideEdgeStyleClasses(edge, side));
styles.add(StyleProvider.WINDING_CLASS);
addStylesIfAny(writer, styles);
List<Point> halfPoints = edge.getPoints(side);
Point point1 = halfPoints.get(halfPoints.size() - 1); // point near 2wt
Point point2 = halfPoints.get(halfPoints.size() - 2); // point near voltage level, or control point for loops
double radius = svgParameters.getTransformerCircleRadius();
Point circleCenter = point1.atDistance(-radius, point2);
writer.writeAttribute("cx", getFormattedValue(circleCenter.getX()));
Expand Down
Loading