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 to enable moving nodes #448

Merged
merged 14 commits into from
Nov 28, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class Graph {
private final org.jgrapht.Graph<Node, Edge> busGraph = new Pseudograph<>(Edge.class);
private final Map<TextEdge, Pair<VoltageLevelNode, TextNode>> textEdges = new LinkedHashMap<>();

private static final String DIAGRAM_ID_SUFFIX_FOR_TEXT_NODE = "-textnode";
private static final String DIAGRAM_ID_SUFFIX_FOR_TEXT_EDGE = "-textedge";

public void addNode(Node node) {
Objects.requireNonNull(node);
nodes.put(node.getEquipmentId(), node);
Expand All @@ -48,7 +51,9 @@ public void addNode(Node node) {

public void addTextNode(VoltageLevelNode vlNode) {
Objects.requireNonNull(vlNode);
addEdge(vlNode, new TextNode(vlNode.getDiagramId() + "_text"), new TextEdge(vlNode.getDiagramId() + "_edge"));
addEdge(vlNode,
new TextNode(vlNode.getDiagramId() + DIAGRAM_ID_SUFFIX_FOR_TEXT_NODE),
new TextEdge(vlNode.getDiagramId() + DIAGRAM_ID_SUFFIX_FOR_TEXT_EDGE));
}

public void addEdge(VoltageLevelNode node1, BusNode busNode1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class SvgWriter {
private static final String Y_ATTRIBUTE = "y";
private static final String DY_ATTRIBUTE = "dy";
private static final String POINTS_ATTRIBUTE = "points";
private static final Map<BranchEdge.Side, Integer> SIDE_END =
new EnumMap<>(Map.of(BranchEdge.Side.ONE, 1, BranchEdge.Side.TWO, 2));
flo-dup marked this conversation as resolved.
Show resolved Hide resolved

private final SvgParameters svgParameters;
private final StyleProvider styleProvider;
Expand Down Expand Up @@ -182,6 +184,7 @@ private void drawHalfEdge(Graph graph, XMLStreamWriter writer, BranchEdge edge,
return;
}
writer.writeStartElement(GROUP_ELEMENT_NAME);
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(edge.getDiagramId() + "." + SIDE_END.get(side)));
addStylesIfAny(writer, styleProvider.getSideEdgeStyleClasses(edge, side));
if (edge.isVisible(side)) {
if (!graph.isLoop(edge)) {
Expand Down Expand Up @@ -477,6 +480,7 @@ private void writeTextNode(XMLStreamWriter writer, TextNode textNode, VoltageLev

private void writeDetailedTextNode(XMLStreamWriter writer, TextNode textNode, VoltageLevelNode vlNode, List<String> content) throws XMLStreamException {
writer.writeStartElement(FOREIGN_OBJECT_ELEMENT_NAME);
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(textNode.getDiagramId()));
writer.writeAttribute(Y_ATTRIBUTE, getFormattedValue(textNode.getY() - svgParameters.getDetailedTextNodeYShift()));
writer.writeAttribute(X_ATTRIBUTE, getFormattedValue(textNode.getX()));

Expand Down Expand Up @@ -532,6 +536,7 @@ private void writeBusNodeLegend(XMLStreamWriter writer, VoltageLevelNode vlNode)

private void writeSimpleTextNode(XMLStreamWriter writer, TextNode textNode, List<String> content) throws XMLStreamException {
writer.writeStartElement(TEXT_ELEMENT_NAME);
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(textNode.getDiagramId()));
writer.writeAttribute(Y_ATTRIBUTE, getFormattedValue(textNode.getY()));
if (content.size() == 1) {
writer.writeAttribute(X_ATTRIBUTE, getFormattedValue(textNode.getX()));
Expand Down Expand Up @@ -789,7 +794,9 @@ 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.getEdgesStream().forEach(edge -> metadata.addEdge(getPrefixedId(edge.getDiagramId()), edge.getEquipmentId(),
getPrefixedId(graph.getNode1(edge).getDiagramId()),
getPrefixedId(graph.getNode2(edge).getDiagramId())));

writer.writeStartElement(METADATA_ELEMENT_NAME);
metadata.writeXml(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void addNode(String svgId, String equipmentId, String positionX, String p
nodesMetadata.add(new NodeMetadata(svgId, equipmentId, positionX, positionY));
}

public void addEdge(String svgId, String equipmentId) {
edgesMetadata.add(new EdgeMetadata(svgId, equipmentId));
public void addEdge(String svgId, String equipmentId, String node1DiagramId, String node2DiagramId) {
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
edgesMetadata.add(new EdgeMetadata(svgId, equipmentId, node1DiagramId, node2DiagramId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,50 @@
*/
package com.powsybl.nad.svg.metadata;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;

/**
* @author Luma Zamarreño <zamarrenolm at aia.es>
*/
public class EdgeMetadata extends AbstractMetadataItem {

private static final String ELEMENT_NAME = "edge";
private static final String NODE1_ATTRIBUTE = "node1";
private static final String NODE2_ATTRIBUTE = "node2";

public EdgeMetadata(String svgId, String equipmentId) {
private final String node1DiagramId;
private final String node2DiagramId;
flo-dup marked this conversation as resolved.
Show resolved Hide resolved

public EdgeMetadata(String svgId, String equipmentId, String node1DiagramId, String node2DiagramId) {
super(svgId, equipmentId);
this.node1DiagramId = node1DiagramId;
this.node2DiagramId = node2DiagramId;
}

@Override
String getElementName() {
return ELEMENT_NAME;
}

@Override
void write(XMLStreamWriter writer) throws XMLStreamException {
super.write(writer);
writer.writeAttribute(NODE1_ATTRIBUTE, node1DiagramId);
writer.writeAttribute(NODE2_ATTRIBUTE, node2DiagramId);
}

static class Reader implements MetadataItemReader<EdgeMetadata> {
@Override
public String getElementName() {
return ELEMENT_NAME;
}

public EdgeMetadata read(XMLStreamReader reader) {
// Read edge-specific metadata
// ...
return new EdgeMetadata(readDiagramId(reader), readEquipmentId(reader));
return new EdgeMetadata(readDiagramId(reader), readEquipmentId(reader),
reader.getAttributeValue(null, NODE1_ATTRIBUTE),
reader.getAttributeValue(null, NODE2_ATTRIBUTE));
}
}
}
14 changes: 7 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.
14 changes: 7 additions & 7 deletions network-area-diagram/src/test/resources/3wt_disconnected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions network-area-diagram/src/test/resources/3wt_partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading