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

Add metadata for 3wt edges and nodes #458

Merged
merged 4 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -21,7 +21,7 @@ public class Graph {

private final Map<String, Node> nodes = new LinkedHashMap<>();
private final Map<String, BusNode> busNodes = new LinkedHashMap<>();
private final Map<String, Edge> edges = new LinkedHashMap<>();
private final Map<String, BranchEdge> branchEdges = new LinkedHashMap<>();
private double minX = 0;
private double minY = 0;
private double maxX = 0;
Expand Down Expand Up @@ -58,6 +58,7 @@ public void addTextNode(VoltageLevelNode vlNode) {

public void addEdge(VoltageLevelNode node1, BusNode busNode1,
VoltageLevelNode node2, BusNode busNode2, BranchEdge edge) {
branchEdges.put(edge.getEquipmentId(), edge);
addVoltageLevelsEdge(node1, node2, edge);
addBusesEdge(busNode1, busNode2, edge);
}
Expand All @@ -78,7 +79,6 @@ private void addVoltageLevelsEdge(Node node1, Node node2, Edge edge) {
Objects.requireNonNull(node1);
Objects.requireNonNull(node2);
Objects.requireNonNull(edge);
edges.put(edge.getEquipmentId(), edge);
voltageLevelGraph.addEdge(node1, node2, edge);
}

Expand Down Expand Up @@ -116,8 +116,12 @@ public Collection<Pair<VoltageLevelNode, TextNode>> getVoltageLevelTextPairs() {
return Collections.unmodifiableCollection(textEdges.values());
}

public Stream<Edge> getEdgesStream() {
return edges.values().stream();
public Stream<BranchEdge> getBranchEdgeStream() {
return branchEdges.values().stream();
}

public Collection<BranchEdge> getBranchEdges() {
return Collections.unmodifiableCollection(branchEdges.values());
}

public Collection<Edge> getEdges() {
Expand All @@ -142,16 +146,6 @@ public Collection<Edge> getBusEdges(BusNode busNode) {
return busGraph.edgesOf(busNode);
}

public Stream<BranchEdge> getBranchEdgeStream() {
return voltageLevelGraph.edgeSet().stream()
.filter(BranchEdge.class::isInstance)
.map(BranchEdge.class::cast);
}

public List<BranchEdge> getBranchEdges() {
return getBranchEdgeStream().collect(Collectors.toList());
}

public Stream<TextEdge> getTextEdgesStream() {
return textEdges.keySet().stream();
}
Expand Down Expand Up @@ -308,7 +302,7 @@ public Node getBusGraphNode2(Edge edge) {
}

public boolean containsEdge(String equipmentId) {
return edges.containsKey(equipmentId);
return branchEdges.containsKey(equipmentId);
}

public boolean containsNode(String equipmentId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void drawBranchEdges(Graph graph, XMLStreamWriter writer) throws XMLStre
for (BranchEdge edge : graph.getBranchEdges()) {
writer.writeStartElement(GROUP_ELEMENT_NAME);
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(edge.getDiagramId()));
addStylesIfAny(writer, styleProvider.getEdgeStyleClasses(edge));
writeStyleClasses(writer, styleProvider.getEdgeStyleClasses(edge));
insertName(writer, edge::getName);

drawHalfEdge(graph, writer, edge, BranchEdge.Side.ONE);
Expand Down Expand Up @@ -205,11 +205,11 @@ private void drawHalfEdge(Graph graph, XMLStreamWriter writer, BranchEdge edge,
}
writer.writeStartElement(GROUP_ELEMENT_NAME);
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(edge.getDiagramId() + "." + side.getNum()));
addStylesIfAny(writer, styleProvider.getSideEdgeStyleClasses(edge, side));
writeStyleClasses(writer, styleProvider.getSideEdgeStyleClasses(edge, side));
if (edge.isVisible(side)) {
if (!graph.isLoop(edge)) {
writer.writeEmptyElement(POLYLINE_ELEMENT_NAME);
writer.writeAttribute(CLASS_ATTRIBUTE, String.join(" ", StyleProvider.EDGE_PATH_CLASS, StyleProvider.STRETCHABLE_CLASS));
writeStyleClasses(writer, 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 Down Expand Up @@ -247,12 +247,15 @@ private void drawThreeWtEdge(Graph graph, XMLStreamWriter writer, ThreeWtEdge ed
}
writer.writeStartElement(GROUP_ELEMENT_NAME);
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(edge.getDiagramId()));
addStylesIfAny(writer, styleProvider.getEdgeStyleClasses(edge));
writeStyleClasses(writer, styleProvider.getEdgeStyleClasses(edge));
insertName(writer, edge::getName);

writer.writeEmptyElement(POLYLINE_ELEMENT_NAME);
writer.writeAttribute(CLASS_ATTRIBUTE, StyleProvider.EDGE_PATH_CLASS);
writeStyleClasses(writer, StyleProvider.EDGE_PATH_CLASS, StyleProvider.STRETCHABLE_CLASS);
writer.writeAttribute(POINTS_ATTRIBUTE, getPolylinePointsString(edge));

drawThreeWtEdgeInfo(graph, writer, edge, labelProvider.getEdgeInfos(graph, edge));

writer.writeEndElement();
}

Expand All @@ -266,7 +269,8 @@ private void drawThreeWtNodes(Graph graph, XMLStreamWriter writer) throws XMLStr
writer.writeAttribute(CLASS_ATTRIBUTE, StyleProvider.THREE_WT_NODES_CLASS);
for (ThreeWtNode threeWtNode : threeWtNodes) {
writer.writeStartElement(GROUP_ELEMENT_NAME);
addStylesIfAny(writer, styleProvider.getNodeStyleClasses(threeWtNode));
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(threeWtNode.getDiagramId()));
writeStyleClasses(writer, styleProvider.getNodeStyleClasses(threeWtNode));
List<ThreeWtEdge> edges = graph.getThreeWtEdgeStream(threeWtNode).collect(Collectors.toList());
for (ThreeWtEdge edge : edges) {
draw3WtWinding(edge, threeWtNode, writer);
Expand All @@ -277,12 +281,10 @@ private void drawThreeWtNodes(Graph graph, XMLStreamWriter writer) throws XMLStr
}

private void draw3WtWinding(ThreeWtEdge edge, ThreeWtNode threeWtNode, XMLStreamWriter writer) throws XMLStreamException {
List<String> styles = styleProvider.getThreeWtNodeStyle(threeWtNode, edge.getSide());
styles.add(StyleProvider.WINDING_CLASS);
double radius = svgParameters.getTransformerCircleRadius();
Point circleCenter = edge.getPoints().get(1).atDistance(radius, threeWtNode.getPosition());
writer.writeEmptyElement(CIRCLE_ELEMENT_NAME);
addStylesIfAny(writer, styles);
writeStyleClasses(writer, styleProvider.getThreeWtNodeStyle(threeWtNode, edge.getSide()), StyleProvider.WINDING_CLASS);
writer.writeAttribute("cx", getFormattedValue(circleCenter.getX()));
writer.writeAttribute("cy", getFormattedValue(circleCenter.getY()));
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(svgParameters.getTransformerCircleRadius()));
Expand All @@ -302,7 +304,8 @@ private void drawBranchEdgeInfo(Graph graph, XMLStreamWriter writer, BranchEdge
private void drawThreeWtEdgeInfo(Graph graph, XMLStreamWriter writer, ThreeWtEdge edge, List<EdgeInfo> edgeInfos) throws XMLStreamException {
VoltageLevelNode vlNode = graph.getVoltageLevelNode(edge);
BusNode busNode = graph.getBusGraphNode(edge);
drawEdgeInfo(writer, edgeInfos, getArrowCenter(vlNode, busNode, edge.getPoints()), edge.getEdgeAngle());
List<String> additionalStyles = List.of(StyleProvider.GLUED_CLASS + "-1");
drawEdgeInfo(writer, additionalStyles, edgeInfos, getArrowCenter(vlNode, busNode, edge.getPoints()), edge.getEdgeAngle());
}

private void drawEdgeInfo(XMLStreamWriter writer, List<EdgeInfo> edgeInfos, Point infoCenter, double edgeAngle) throws XMLStreamException {
Expand All @@ -311,13 +314,11 @@ private void drawEdgeInfo(XMLStreamWriter writer, List<EdgeInfo> edgeInfos, Poin

private void drawEdgeInfo(XMLStreamWriter writer, List<String> additionalStyles, List<EdgeInfo> edgeInfos, Point infoCenter, double edgeAngle) throws XMLStreamException {
writer.writeStartElement(GROUP_ELEMENT_NAME);
List<String> styles = new ArrayList<>(additionalStyles);
styles.add(StyleProvider.EDGE_INFOS_CLASS);
writer.writeAttribute(CLASS_ATTRIBUTE, String.join(" ", styles));
writeStyleClasses(writer, additionalStyles, StyleProvider.EDGE_INFOS_CLASS);
writer.writeAttribute(TRANSFORM_ATTRIBUTE, getTranslateString(infoCenter));
for (EdgeInfo info : edgeInfos) {
writer.writeStartElement(GROUP_ELEMENT_NAME);
addStylesIfAny(writer, styleProvider.getEdgeInfoStyles(info));
writeStyleClasses(writer, styleProvider.getEdgeInfoStyles(info));
drawInAndOutArrows(writer, edgeAngle);
Optional<String> externalLabel = info.getExternalLabel();
if (externalLabel.isPresent()) {
Expand Down Expand Up @@ -424,9 +425,7 @@ private Point getArrowCenter(VoltageLevelNode vlNode, BusNode busNode, List<Poin

private void draw2WtWinding(XMLStreamWriter writer, BranchEdge edge, BranchEdge.Side side) throws XMLStreamException {
writer.writeEmptyElement(CIRCLE_ELEMENT_NAME);
List<String> styles = new ArrayList<>(styleProvider.getSideEdgeStyleClasses(edge, side));
styles.add(StyleProvider.WINDING_CLASS);
addStylesIfAny(writer, styles);
writeStyleClasses(writer, styleProvider.getSideEdgeStyleClasses(edge, side), StyleProvider.WINDING_CLASS);
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
Expand Down Expand Up @@ -549,9 +548,7 @@ private void writeBusNodeLegend(XMLStreamWriter writer, VoltageLevelNode vlNode)
writer.writeStartElement(TABLE_ROW_ELEMENT_NAME);
writer.writeStartElement(TABLE_DATA_ELEMENT_NAME);
writer.writeEmptyElement(DIV_ELEMENT_NAME);
List<String> styles = styleProvider.getNodeStyleClasses(busNode);
styles.add(StyleProvider.LEGEND_SQUARE_CLASS);
writer.writeAttribute(CLASS_ATTRIBUTE, String.join(" ", styles));
writeStyleClasses(writer, styleProvider.getNodeStyleClasses(busNode), StyleProvider.LEGEND_SQUARE_CLASS);
writer.writeEndElement();
writer.writeStartElement(TABLE_DATA_ELEMENT_NAME);
writer.writeCharacters(labelProvider.getBusDescription(busNode));
Expand Down Expand Up @@ -585,14 +582,14 @@ private void writeSimpleTextNode(XMLStreamWriter writer, TextNode textNode, List

private void drawNode(Graph graph, XMLStreamWriter writer, VoltageLevelNode vlNode) throws XMLStreamException {
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(vlNode.getDiagramId()));
addStylesIfAny(writer, styleProvider.getNodeStyleClasses(vlNode));
writeStyleClasses(writer, styleProvider.getNodeStyleClasses(vlNode));
insertName(writer, vlNode::getName);

double nodeOuterRadius = getVoltageLevelCircleRadius(vlNode);

if (vlNode.hasUnknownBusNode()) {
writer.writeEmptyElement(CIRCLE_ELEMENT_NAME);
addStylesIfAny(writer, styleProvider.getNodeStyleClasses(BusNode.UNKNOWN));
writeStyleClasses(writer, styleProvider.getNodeStyleClasses(BusNode.UNKNOWN));
writer.writeAttribute(CIRCLE_RADIUS_ATTRIBUTE, getFormattedValue(nodeOuterRadius + svgParameters.getUnknownBusNodeExtraRadius()));
}

Expand All @@ -615,10 +612,7 @@ private void drawNode(Graph graph, XMLStreamWriter writer, VoltageLevelNode vlNo
writer.writeAttribute(PATH_D_ATTRIBUTE, getFragmentedAnnulusPath(busInnerRadius, busOuterRadius, traversingBusEdges, graph, vlNode, busNode));
}
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(busNode.getDiagramId()));

List<String> nodeStyleClasses = new ArrayList<>(styleProvider.getNodeStyleClasses(busNode));
nodeStyleClasses.add(StyleProvider.BUSNODE_CLASS);
addStylesIfAny(writer, nodeStyleClasses);
writeStyleClasses(writer, styleProvider.getNodeStyleClasses(busNode), StyleProvider.BUSNODE_CLASS);

traversingBusEdges.addAll(graph.getBusEdges(busNode));
}
Expand Down Expand Up @@ -739,7 +733,7 @@ private void drawTextEdges(Graph graph, XMLStreamWriter writer) throws XMLStream
private void drawTextEdge(XMLStreamWriter writer, TextEdge edge, VoltageLevelNode vlNode) throws XMLStreamException {
writer.writeEmptyElement(POLYLINE_ELEMENT_NAME);
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(edge.getDiagramId()));
addStylesIfAny(writer, styleProvider.getEdgeStyleClasses(edge));
writeStyleClasses(writer, styleProvider.getEdgeStyleClasses(edge));
List<Point> points = edge.getPoints();
shiftEdgeStart(points, vlNode);
String lineFormatted1 = points.stream()
Expand All @@ -748,10 +742,17 @@ private void drawTextEdge(XMLStreamWriter writer, TextEdge edge, VoltageLevelNod
writer.writeAttribute(POINTS_ATTRIBUTE, lineFormatted1);
}

private void addStylesIfAny(XMLStreamWriter writer, List<String> edgeStyleClasses) throws XMLStreamException {
if (!edgeStyleClasses.isEmpty()) {
writer.writeAttribute(CLASS_ATTRIBUTE, String.join(" ", edgeStyleClasses));
private void writeStyleClasses(XMLStreamWriter writer, String... additionalClasses) throws XMLStreamException {
writeStyleClasses(writer, Collections.emptyList(), additionalClasses);
}

private void writeStyleClasses(XMLStreamWriter writer, List<String> edgeStyleClasses, String... additionalClasses) throws XMLStreamException {
if (edgeStyleClasses.isEmpty() && additionalClasses.length == 0) {
return;
}
List<String> allClasses = new ArrayList<>(edgeStyleClasses);
allClasses.addAll(Arrays.asList(additionalClasses));
writer.writeAttribute(CLASS_ATTRIBUTE, String.join(" ", allClasses));
}

private void shiftEdgeStart(List<Point> points, VoltageLevelNode vlNode) {
Expand Down Expand Up @@ -834,7 +835,10 @@ private void addMetadata(Graph graph, XMLStreamWriter writer) throws XMLStreamEx
graph.getBusNodesStream().forEach(busNode -> metadata.addBusNode(getPrefixedId(busNode.getDiagramId()), busNode.getEquipmentId()));
graph.getNodesStream().forEach(node -> metadata.addNode(getPrefixedId(node.getDiagramId()), node.getEquipmentId(),
getFormattedValue(node.getX()), getFormattedValue(node.getY())));
graph.getEdgesStream().forEach(edge -> metadata.addEdge(getPrefixedId(edge.getDiagramId()), edge.getEquipmentId(),
graph.getBranchEdgeStream().forEach(edge -> metadata.addEdge(getPrefixedId(edge.getDiagramId()), edge.getEquipmentId(),
getPrefixedId(graph.getNode1(edge).getDiagramId()),
getPrefixedId(graph.getNode2(edge).getDiagramId())));
graph.getThreeWtEdgesStream().forEach(edge -> metadata.addEdge(getPrefixedId(edge.getDiagramId()), edge.getEquipmentId(),
getPrefixedId(graph.getNode1(edge).getDiagramId()),
getPrefixedId(graph.getNode2(edge).getDiagramId())));

Expand Down
16 changes: 9 additions & 7 deletions network-area-diagram/src/test/resources/3wt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading