From 42f6184f1a9952010489c2e8ad6cc9eb5681519a Mon Sep 17 00:00:00 2001 From: "massimo.ferraro" Date: Fri, 20 Sep 2024 16:45:38 +0200 Subject: [PATCH 1/7] Save network area diagram metadata in json format Signed-off-by: massimo.ferraro --- .../com/powsybl/nad/NetworkAreaDiagram.java | 51 +- .../java/com/powsybl/nad/svg/Padding.java | 6 +- .../com/powsybl/nad/svg/SvgParameters.java | 17 + .../java/com/powsybl/nad/svg/SvgWriter.java | 61 -- .../svg/metadata/AbstractMetadataItem.java | 34 +- .../nad/svg/metadata/BusNodeMetadata.java | 63 +- .../nad/svg/metadata/DiagramMetadata.java | 269 +++++---- .../nad/svg/metadata/EdgeMetadata.java | 74 +-- .../metadata/LayoutParametersMetadata.java | 93 --- .../nad/svg/metadata/NodeMetadata.java | 62 +- .../svg/metadata/SvgParametersMetadata.java | 269 --------- .../nad/svg/metadata/TextNodeMetadata.java | 82 +-- .../LayoutWithInitialPositionsTest.java | 3 +- .../powsybl/nad/svg/DiagramMetadataTest.java | 113 ++-- .../src/test/resources/3wt.svg | 27 - .../src/test/resources/3wt_disconnected.svg | 26 - .../3wt_disconnected_topological.svg | 26 - .../src/test/resources/3wt_metadata.json | 148 +++++ .../src/test/resources/3wt_partial.svg | 25 - .../src/test/resources/IEEE_118_bus.svg | 554 ------------------ .../test/resources/IEEE_118_bus_partial.svg | 146 ----- .../IEEE_118_bus_partial_non_connected.svg | 107 ---- .../src/test/resources/IEEE_14_bus.svg | 70 --- .../resources/IEEE_14_bus_disconnection.svg | 67 --- .../test/resources/IEEE_14_bus_fictitious.svg | 76 --- .../test/resources/IEEE_14_bus_text_nodes.svg | 76 --- .../resources/IEEE_14_bus_voltage_filter1.svg | 45 -- .../resources/IEEE_14_bus_voltage_filter2.svg | 72 --- .../resources/IEEE_14_bus_voltage_filter3.svg | 53 -- .../resources/IEEE_14_bus_voltage_filter4.svg | 58 -- .../resources/IEEE_14_bus_voltage_filter5.svg | 49 -- .../test/resources/IEEE_14_id_prefixed.svg | 76 --- .../src/test/resources/IEEE_24_bus.svg | 124 ---- .../src/test/resources/IEEE_30_bus.svg | 145 ----- .../src/test/resources/IEEE_57_bus.svg | 235 -------- .../src/test/resources/current_limits.svg | 24 - .../resources/dangling_line_connected.svg | 32 - .../resources/dangling_line_disconnected.svg | 32 - .../src/test/resources/detailed_text_node.svg | 24 - .../detailed_text_node_no_legend.svg | 24 - .../diamond-spring-repulsion-factor-0.0.svg | 75 --- .../diamond-spring-repulsion-factor-0.2.svg | 75 --- .../src/test/resources/edge_info_current.svg | 24 - .../resources/edge_info_double_labels.svg | 27 - .../resources/edge_info_missing_label.svg | 24 - .../edge_info_perpendicular_label.svg | 24 - .../resources/edge_info_reactive_power.svg | 24 - .../src/test/resources/edge_info_shift.svg | 32 - .../src/test/resources/edge_with_id.svg | 32 - .../src/test/resources/edge_without_id.svg | 32 - .../src/test/resources/hvdc-vl-depth-1.svg | 21 - .../src/test/resources/hvdc.svg | 34 -- .../src/test/resources/hvdc_metadata.json | 197 +++++++ .../test/resources/parallel_transformers.svg | 26 - .../production_consumption_text_node.svg | 32 - .../production_consumption_text_node_nan.svg | 32 - .../src/test/resources/simple-eu-loop100.svg | 64 -- .../src/test/resources/simple-eu-loop80.svg | 64 -- .../src/test/resources/simple-eu.svg | 64 -- .../src/test/resources/tie_line.svg | 30 - .../src/test/resources/tie_line_filtered.svg | 29 - .../src/test/resources/vl_description_id.svg | 24 - .../resources/vl_description_substation.svg | 24 - .../vl_description_substation_id.svg | 24 - .../src/test/resources/voltage_limits.svg | 26 - 65 files changed, 695 insertions(+), 3903 deletions(-) delete mode 100644 network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/LayoutParametersMetadata.java delete mode 100644 network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/SvgParametersMetadata.java create mode 100644 network-area-diagram/src/test/resources/3wt_metadata.json create mode 100644 network-area-diagram/src/test/resources/hvdc_metadata.json diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index f8d58f298..4dfdd163c 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -15,6 +15,7 @@ import com.powsybl.nad.model.Graph; import com.powsybl.nad.svg.SvgParameters; import com.powsybl.nad.svg.SvgWriter; +import com.powsybl.nad.svg.metadata.DiagramMetadata; import java.io.IOException; import java.io.StringWriter; @@ -37,45 +38,53 @@ public static void draw(Network network, Path svgFile) { draw(network, svgFile, new NadParameters(), VoltageLevelFilter.NO_FILTER); } - public static void draw(Network network, Writer writer) { - draw(network, writer, new NadParameters(), VoltageLevelFilter.NO_FILTER); + public static void draw(Network network, Writer writer, Writer metadataWriter) { + draw(network, writer, metadataWriter, new NadParameters(), VoltageLevelFilter.NO_FILTER); } public static void draw(Network network, Path svgFile, String voltageLevelId, int depth) { draw(network, svgFile, new NadParameters(), VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth)); } - public static void draw(Network network, Writer writer, String voltageLevelId, int depth) { - draw(network, writer, new NadParameters(), VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth)); + public static void draw(Network network, Writer writer, Writer metadataWriter, String voltageLevelId, int depth) { + draw(network, writer, metadataWriter, new NadParameters(), VoltageLevelFilter.createVoltageLevelDepthFilter(network, voltageLevelId, depth)); } public static void draw(Network network, Path svgFile, List voltageLevelIds) { draw(network, svgFile, new NadParameters(), VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds)); } - public static void draw(Network network, Writer writer, List voltageLevelIds) { - draw(network, writer, new NadParameters(), VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds)); + public static void draw(Network network, Writer writer, Writer metadataWriter, List voltageLevelIds) { + draw(network, writer, metadataWriter, new NadParameters(), VoltageLevelFilter.createVoltageLevelsFilter(network, voltageLevelIds)); } public static void draw(Network network, Path svgFile, List voltageLevelIds, int depth) { draw(network, svgFile, new NadParameters(), VoltageLevelFilter.createVoltageLevelsDepthFilter(network, voltageLevelIds, depth)); } - public void draw(Network network, Writer writer, Predicate voltageLevelFilter) { - draw(network, writer, new NadParameters(), voltageLevelFilter); + public void draw(Network network, Writer writer, Writer metadataWriter, Predicate voltageLevelFilter) { + draw(network, writer, metadataWriter, new NadParameters(), voltageLevelFilter); } public static void draw(Network network, Path svgFile, NadParameters param, Predicate voltageLevelFilter) { - genericDraw(network, svgFile, param, voltageLevelFilter); + Objects.requireNonNull(svgFile); + Path dir = svgFile.toAbsolutePath().getParent(); + String svgFileName = svgFile.getFileName().toString(); + if (!svgFileName.endsWith(".svg")) { + svgFileName = svgFileName + ".svg"; + } + Path metadataFile = dir.resolve(svgFileName.replace(".svg", "_metadata.json")); + genericDraw(network, svgFile, metadataFile, param, voltageLevelFilter); } - public static void draw(Network network, Writer writer, NadParameters param, Predicate voltageLevelFilter) { - genericDraw(network, writer, param, voltageLevelFilter); + public static void draw(Network network, Writer writer, Writer metadataWriter, NadParameters param, Predicate voltageLevelFilter) { + genericDraw(network, writer, metadataWriter, param, voltageLevelFilter); } - private static void genericDraw(Network network, Object object, NadParameters param, Predicate voltageLevelFilter) { + private static void genericDraw(Network network, Object svgObject, Object metadataObject, NadParameters param, Predicate voltageLevelFilter) { Objects.requireNonNull(network); - Objects.requireNonNull(object); + Objects.requireNonNull(svgObject); + Objects.requireNonNull(metadataObject); Objects.requireNonNull(param); Objects.requireNonNull(voltageLevelFilter); @@ -83,20 +92,28 @@ private static void genericDraw(Network network, Object object, NadParameters pa param.getLayoutFactory().create().run(graph, param.getLayoutParameters()); SvgWriter svgWriter = new SvgWriter(param.getSvgParameters(), param.getStyleProviderFactory().create(network), param.createLabelProvider(network), param.getLayoutParameters()); + DiagramMetadata metadata = new DiagramMetadata(param.getLayoutParameters(), param.getSvgParameters()); - if (object instanceof Path svgFile) { + if (svgObject instanceof Path svgFile) { svgWriter.writeSvg(graph, svgFile); - } else if (object instanceof Writer writer) { + } else if (svgObject instanceof Writer writer) { svgWriter.writeSvg(graph, writer); } else { throw new PowsyblException("Second argument is an instance of an unexpected class"); } + if (metadataObject instanceof Path metadataFile) { + metadata.addMetadata(graph).writeJson(metadataFile); + } else if (metadataObject instanceof Writer metadataWriter) { + metadata.addMetadata(graph).writeJson(metadataWriter); + } else { + throw new PowsyblException("Third argument is an instance of an unexpected class"); + } } public String drawToString(Network network, SvgParameters svgParameters) { - try (StringWriter writer = new StringWriter()) { + try (StringWriter writer = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { NadParameters nadParameters = new NadParameters().setSvgParameters(svgParameters); - draw(network, writer, nadParameters, VoltageLevelFilter.NO_FILTER); + draw(network, writer, metadataWriter, nadParameters, VoltageLevelFilter.NO_FILTER); return writer.toString(); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/Padding.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/Padding.java index b37049f42..bb1c3d697 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/Padding.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/Padding.java @@ -6,6 +6,9 @@ */ package com.powsybl.nad.svg; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * @author Florian Dupuy {@literal } */ @@ -16,7 +19,8 @@ public class Padding { private double right; private double bottom; - public Padding(double left, double top, double right, double bottom) { + @JsonCreator + public Padding(@JsonProperty("left") double left, @JsonProperty("top") double top, @JsonProperty("right") double right, @JsonProperty("bottom") double bottom) { this.left = left; this.top = top; this.right = right; diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java index df0ae2e9a..9d4d067be 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java @@ -6,6 +6,7 @@ */ package com.powsybl.nad.svg; +import com.fasterxml.jackson.annotation.JsonGetter; import com.powsybl.diagram.util.ValueFormatter; import java.util.Locale; @@ -33,10 +34,12 @@ public class SvgParameters { private double nodeHollowWidth = 15; private double edgesForkLength = 80; private double edgesForkAperture = Math.toRadians(60); + private double edgesForkApertureDegrees = 60; private double edgeStartShift = 0; private double unknownBusNodeExtraRadius = 10; private double loopDistance = 120; private double loopEdgesAperture = Math.toRadians(60); + private double loopEdgesApertureDegrees = 60; private double loopControlDistance = 40; private boolean edgeInfoAlongEdge = true; private boolean edgeNameDisplayed = false; @@ -86,10 +89,12 @@ public SvgParameters(SvgParameters other) { this.nodeHollowWidth = other.nodeHollowWidth; this.edgesForkLength = other.edgesForkLength; this.edgesForkAperture = other.edgesForkAperture; + this.edgesForkApertureDegrees = other.edgesForkApertureDegrees; this.edgeStartShift = other.edgeStartShift; this.unknownBusNodeExtraRadius = other.unknownBusNodeExtraRadius; this.loopDistance = other.loopDistance; this.loopEdgesAperture = other.loopEdgesAperture; + this.loopEdgesApertureDegrees = other.loopEdgesApertureDegrees; this.loopControlDistance = other.loopControlDistance; this.edgeInfoAlongEdge = other.edgeInfoAlongEdge; this.edgeNameDisplayed = other.edgeNameDisplayed; @@ -245,18 +250,30 @@ public double getEdgesForkAperture() { public SvgParameters setEdgesForkAperture(double edgesForkApertureDegrees) { this.edgesForkAperture = Math.toRadians(edgesForkApertureDegrees); + this.edgesForkApertureDegrees = edgesForkApertureDegrees; return this; } + @JsonGetter("edgesForkAperture") + public double getEdgesForkApertureDegrees() { + return edgesForkApertureDegrees; + } + public double getLoopEdgesAperture() { return loopEdgesAperture; } public SvgParameters setLoopEdgesAperture(double loopEdgesApertureDegrees) { this.loopEdgesAperture = Math.toRadians(loopEdgesApertureDegrees); + this.loopEdgesApertureDegrees = loopEdgesApertureDegrees; return this; } + @JsonGetter("loopEdgesAperture") + public double getLoopEdgesApertureDegrees() { + return loopEdgesApertureDegrees; + } + public double getEdgesForkLength() { return edgesForkLength; } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java index bf032fc53..ae5b6c0cb 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java @@ -10,7 +10,6 @@ import com.powsybl.commons.xml.XmlUtil; import com.powsybl.nad.layout.LayoutParameters; import com.powsybl.nad.model.*; -import com.powsybl.nad.svg.metadata.DiagramMetadata; import org.apache.commons.io.output.WriterOutputStream; import org.jgrapht.alg.util.Pair; @@ -35,7 +34,6 @@ public class SvgWriter { public static final String XHTML_NAMESPACE_URI = "http://www.w3.org/1999/xhtml"; private static final String SVG_ROOT_ELEMENT_NAME = "svg"; private static final String STYLE_ELEMENT_NAME = "style"; - private static final String METADATA_ELEMENT_NAME = "metadata"; private static final String GROUP_ELEMENT_NAME = "g"; private static final String POLYLINE_ELEMENT_NAME = "polyline"; private static final String PATH_ELEMENT_NAME = "path"; @@ -109,7 +107,6 @@ private void writeSvg(Graph graph, OutputStream svgOs) { XMLStreamWriter writer = XmlUtil.initializeWriter(true, INDENT, svgOs); addSvgRoot(graph, writer); addStyle(writer); - addMetadata(graph, writer); drawVoltageLevelNodes(graph, writer); drawBranchEdges(graph, writer); drawThreeWtEdges(graph, writer); @@ -898,64 +895,6 @@ private void addStyle(XMLStreamWriter writer) throws XMLStreamException { } } - private void addMetadata(Graph graph, XMLStreamWriter writer) throws XMLStreamException { - DiagramMetadata metadata = new DiagramMetadata(); - - graph.getVoltageLevelNodesStream().forEach(vlNode -> vlNode.getBusNodeStream().forEach(busNode -> metadata.addBusNode( - getPrefixedId(busNode.getDiagramId()), - busNode.getEquipmentId(), - String.valueOf(busNode.getNbNeighbouringBusNodes()), - String.valueOf(busNode.getRingIndex()), - getPrefixedId(vlNode.getDiagramId())))); - graph.getNodesStream().forEach(node -> metadata.addNode(getPrefixedId(node.getDiagramId()), node.getEquipmentId(), - getFormattedValue(node.getX()), getFormattedValue(node.getY()))); - graph.getBranchEdgeStream().forEach(edge -> metadata.addEdge(getPrefixedId(edge.getDiagramId()), edge.getEquipmentId(), - getPrefixedId(graph.getNode1(edge).getDiagramId()), - getPrefixedId(graph.getNode2(edge).getDiagramId()), - getPrefixedId(graph.getBusGraphNode1(edge).getDiagramId()), - getPrefixedId(graph.getBusGraphNode2(edge).getDiagramId()), - edge.getType())); - graph.getThreeWtEdgesStream().forEach(edge -> metadata.addEdge(getPrefixedId(edge.getDiagramId()), edge.getEquipmentId(), - getPrefixedId(graph.getNode1(edge).getDiagramId()), - getPrefixedId(graph.getNode2(edge).getDiagramId()), - getPrefixedId(graph.getBusGraphNode1(edge).getDiagramId()), - getPrefixedId(graph.getBusGraphNode2(edge).getDiagramId()), - edge.getType())); - graph.getVoltageLevelTextPairs().forEach(textPair -> metadata.addTextNode(getPrefixedId(textPair.getSecond().getDiagramId()), - textPair.getFirst().getEquipmentId(), - getPrefixedId(textPair.getFirst().getDiagramId()), - getFormattedValue(textPair.getSecond().getX() - textPair.getFirst().getX()), - getFormattedValue(textPair.getSecond().getY() - textPair.getFirst().getY()), - getFormattedValue(textPair.getSecond().getEdgeConnection().getX() - textPair.getFirst().getX()), - getFormattedValue(textPair.getSecond().getEdgeConnection().getY() - textPair.getFirst().getY()))); - metadata.addSvgParameters(String.valueOf(svgParameters.isInsertNameDesc()), String.valueOf(svgParameters.isSvgWidthAndHeightAdded()), - svgParameters.getCssLocation().name(), svgParameters.getSizeConstraint().name(), - String.valueOf(svgParameters.getFixedWidth()), String.valueOf(svgParameters.getFixedHeight()), - String.valueOf(svgParameters.getFixedScale()), String.valueOf(svgParameters.getArrowShift()), - String.valueOf(svgParameters.getArrowLabelShift()), String.valueOf(svgParameters.getConverterStationWidth()), - String.valueOf(svgParameters.getVoltageLevelCircleRadius()), - String.valueOf(svgParameters.getFictitiousVoltageLevelCircleRadius()), - String.valueOf(svgParameters.getTransformerCircleRadius()), String.valueOf(svgParameters.getNodeHollowWidth()), - String.valueOf(svgParameters.getEdgesForkLength()), String.valueOf(svgParameters.getEdgesForkAperture()), - String.valueOf(svgParameters.getEdgeStartShift()), String.valueOf(svgParameters.getUnknownBusNodeExtraRadius()), - String.valueOf(svgParameters.getLoopDistance()), String.valueOf(svgParameters.getLoopEdgesAperture()), - String.valueOf(svgParameters.getLoopControlDistance()), String.valueOf(svgParameters.isEdgeInfoAlongEdge()), - String.valueOf(svgParameters.isEdgeNameDisplayed()), String.valueOf(svgParameters.getInterAnnulusSpace()), - svgParameters.getSvgPrefix(), String.valueOf(svgParameters.isIdDisplayed()), - String.valueOf(svgParameters.isSubstationDescriptionDisplayed()), String.valueOf(svgParameters.getArrowHeight()), - String.valueOf(svgParameters.isBusLegend()), String.valueOf(svgParameters.isVoltageLevelDetails()), - svgParameters.getLanguageTag(), String.valueOf(svgParameters.getVoltageValuePrecision()), - String.valueOf(svgParameters.getPowerValuePrecision()), String.valueOf(svgParameters.getAngleValuePrecision()), - String.valueOf(svgParameters.getCurrentValuePrecision()), svgParameters.getEdgeInfoDisplayed().name(), - String.valueOf(svgParameters.getPstArrowHeadSize()), svgParameters.getUndefinedValueSymbol()); - metadata.addLayoutParameters(String.valueOf(layoutParameters.isTextNodesForceLayout()), String.valueOf(layoutParameters.getSpringRepulsionFactorForceLayout()), - String.valueOf(layoutParameters.getTextNodeFixedShift().getX()), String.valueOf(layoutParameters.getTextNodeFixedShift().getY()), - String.valueOf(layoutParameters.getMaxSteps()), String.valueOf(layoutParameters.getTextNodeEdgeConnectionYShift())); - writer.writeStartElement(METADATA_ELEMENT_NAME); - metadata.writeXml(writer); - writer.writeEndElement(); - } - private static String getFormattedValue(double value) { return String.format(Locale.US, "%.2f", value); } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/AbstractMetadataItem.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/AbstractMetadataItem.java index fdfa1eda5..aa1eaedcf 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/AbstractMetadataItem.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/AbstractMetadataItem.java @@ -7,44 +7,28 @@ */ package com.powsybl.nad.svg.metadata; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Luma Zamarreño {@literal } */ public abstract class AbstractMetadataItem { - private static final String DIAGRAM_ID_ATTRIBUTE = "svgId"; - private static final String EQUIPMENT_ID_ATTRIBUTE = "equipmentId"; - private final String svgId; private final String equipmentId; - protected AbstractMetadataItem(String svgId, String equipmentId) { + protected AbstractMetadataItem(@JsonProperty("svgId") String svgId, + @JsonProperty("equipmentId") String equipmentId) { this.svgId = svgId; this.equipmentId = equipmentId; } - abstract String getElementName(); - - void write(XMLStreamWriter writer) throws XMLStreamException { - writer.writeEmptyElement(DiagramMetadata.METADATA_PREFIX, getElementName(), DiagramMetadata.METADATA_NAMESPACE_URI); - writer.writeAttribute(DIAGRAM_ID_ATTRIBUTE, svgId); - writer.writeAttribute(EQUIPMENT_ID_ATTRIBUTE, equipmentId); - } - - interface MetadataItemReader { - String getElementName(); - - I read(XMLStreamReader reader); - } - - static String readDiagramId(XMLStreamReader reader) { - return reader.getAttributeValue(null, DIAGRAM_ID_ATTRIBUTE); + @JsonProperty("svgId") + public String getSvgId() { + return svgId; } - static String readEquipmentId(XMLStreamReader reader) { - return reader.getAttributeValue(null, EQUIPMENT_ID_ATTRIBUTE); + @JsonProperty("equipmentId") + public String getEquipmentId() { + return equipmentId; } } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java index 948d48110..67ace5652 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/BusNodeMetadata.java @@ -1,71 +1,48 @@ -package com.powsybl.nad.svg.metadata; - /** * Copyright (c) 2022, RTE (http://www.rte-france.com) * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.xml.XmlUtil; +package com.powsybl.nad.svg.metadata; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; /** * * @author Florian Dupuy {@literal } */ - +@JsonInclude(JsonInclude.Include.NON_NULL) public class BusNodeMetadata extends AbstractMetadataItem { - private static final String ELEMENT_NAME = "busNode"; - private static final String NB_NEIGHBOURS_ATTRIBUTE = "nbNeighbours"; - private static final String INDEX_ATTRIBUTE = "index"; - private static final String VL_NODE_ATTRIBUTE = "vlNode"; - private final String nbNeighbours; - private final String index; + private final int nbNeighbours; + private final int index; private final String vlNodeId; - public BusNodeMetadata(String svgId, String equipmentId, String nbNeighbours, String index, String vlNodeId) { + public BusNodeMetadata(@JsonProperty("svgId") String svgId, + @JsonProperty("equipmentId") String equipmentId, + @JsonProperty("nbNeighbours") int nbNeighbours, + @JsonProperty("index") int index, + @JsonProperty("vlNode") String vlNodeId) { super(svgId, equipmentId); this.nbNeighbours = nbNeighbours; this.index = index; this.vlNodeId = vlNodeId; } - @Override - String getElementName() { - return ELEMENT_NAME; + @JsonProperty("nbNeighbours") + public int getNbNeighbours() { + return nbNeighbours; } - @Override - void write(XMLStreamWriter writer) throws XMLStreamException { - super.write(writer); - writer.writeAttribute(NB_NEIGHBOURS_ATTRIBUTE, nbNeighbours); - writer.writeAttribute(INDEX_ATTRIBUTE, index); - writer.writeAttribute(VL_NODE_ATTRIBUTE, vlNodeId); + @JsonProperty("index") + public int getIndex() { + return index; } - static class Reader implements AbstractMetadataItem.MetadataItemReader { - @Override - public String getElementName() { - return ELEMENT_NAME; - } - - public BusNodeMetadata read(XMLStreamReader reader) { - try { - String diagramId = readDiagramId(reader); - String equipmentId = readEquipmentId(reader); - String nbNeighbours = reader.getAttributeValue(null, NB_NEIGHBOURS_ATTRIBUTE); - String index = reader.getAttributeValue(null, INDEX_ATTRIBUTE); - String vlNodeId = reader.getAttributeValue(null, VL_NODE_ATTRIBUTE); - XmlUtil.readEndElementOrThrow(reader); - return new BusNodeMetadata(diagramId, equipmentId, nbNeighbours, index, vlNodeId); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - } + @JsonProperty("vlNode") + public String getVlNodeId() { + return vlNodeId; } } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java index cecf79443..44e5eed81 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java @@ -7,147 +7,188 @@ */ package com.powsybl.nad.svg.metadata; -import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.xml.XmlUtil; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; +import java.io.IOException; import java.io.InputStream; +import java.io.Reader; +import java.io.UncheckedIOException; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Objects; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.powsybl.commons.json.JsonUtil; +import com.powsybl.nad.layout.LayoutParameters; +import com.powsybl.nad.model.Graph; +import com.powsybl.nad.svg.SvgParameters; /** * @author Thomas Adam {@literal } */ public class DiagramMetadata { - static final String METADATA_NAMESPACE_URI = "http://www.powsybl.org/schema/nad-metadata/1_0"; - static final String METADATA_PREFIX = "nad"; - - private static final String METADATA_DIAGRAM_ELEMENT_NAME = "nad"; - private static final String METADATA_BUS_NODES_ELEMENT_NAME = "busNodes"; - private static final String METADATA_NODES_ELEMENT_NAME = "nodes"; - private static final String METADATA_EDGES_ELEMENT_NAME = "edges"; - private static final String METADATA_TEXT_NODES_ELEMENT_NAME = "textNodes"; - private static final String METADATA_SVG_PARAMETERS_ELEMENT_NAME = "svgParameters"; - private static final String METADATA_LAYOUT_PARAMETERS_ELEMENT_NAME = "layoutParameters"; - + private final LayoutParameters layoutParameters; + private final SvgParameters svgParameters; private final List busNodesMetadata = new ArrayList<>(); private final List nodesMetadata = new ArrayList<>(); private final List edgesMetadata = new ArrayList<>(); private final List textNodesMetadata = new ArrayList<>(); - private SvgParametersMetadata svgParametersMetadata; - private LayoutParametersMetadata layoutParametersMetadata; - - public static DiagramMetadata readFromSvg(InputStream inputStream) throws XMLStreamException { - return readFromSvg(XMLInputFactory.newDefaultFactory().createXMLStreamReader(inputStream)); - } - - public static DiagramMetadata readFromSvg(XMLStreamReader reader) throws XMLStreamException { - DiagramMetadata metadata = new DiagramMetadata(); - - XmlUtil.readUntilStartElement("/svg/metadata/nad", reader, metadataToken -> - XmlUtil.readSubElements(reader, token -> { - switch (token) { - case METADATA_BUS_NODES_ELEMENT_NAME -> readCollection(metadata.busNodesMetadata, new BusNodeMetadata.Reader(), reader); - case METADATA_NODES_ELEMENT_NAME -> readCollection(metadata.nodesMetadata, new NodeMetadata.Reader(), reader); - case METADATA_EDGES_ELEMENT_NAME -> readCollection(metadata.edgesMetadata, new EdgeMetadata.Reader(), reader); - case METADATA_TEXT_NODES_ELEMENT_NAME -> readCollection(metadata.textNodesMetadata, new TextNodeMetadata.Reader(), reader); - case METADATA_SVG_PARAMETERS_ELEMENT_NAME -> metadata.svgParametersMetadata = new SvgParametersMetadata.Reader().read(reader); - case METADATA_LAYOUT_PARAMETERS_ELEMENT_NAME -> metadata.layoutParametersMetadata = new LayoutParametersMetadata.Reader().read(reader); - default -> throw new PowsyblException("Unexpected element '" + token + "' in metadata"); - } - }) - ); - return metadata; - } - - private static > void readCollection( - Collection items, - R itemReader, - XMLStreamReader reader) { - XmlUtil.readSubElements(reader, token -> { - if (token.equals(itemReader.getElementName())) { - items.add(itemReader.read(reader)); - } - }); - } - - public void writeXml(XMLStreamWriter writer) throws XMLStreamException { - writer.writeStartElement(METADATA_PREFIX, METADATA_DIAGRAM_ELEMENT_NAME, METADATA_NAMESPACE_URI); - writer.writeNamespace(METADATA_PREFIX, METADATA_NAMESPACE_URI); - - writeCollection(busNodesMetadata, METADATA_BUS_NODES_ELEMENT_NAME, writer); - writeCollection(nodesMetadata, METADATA_NODES_ELEMENT_NAME, writer); - writeCollection(edgesMetadata, METADATA_EDGES_ELEMENT_NAME, writer); - writeCollection(textNodesMetadata, METADATA_TEXT_NODES_ELEMENT_NAME, writer); - if (svgParametersMetadata != null) { - svgParametersMetadata.write(writer); - } else { - SvgParametersMetadata.writeEmpty(writer); + + public DiagramMetadata(LayoutParameters layoutParameters, SvgParameters svgParameters) { + this.layoutParameters = Objects.requireNonNull(layoutParameters); + this.svgParameters = Objects.requireNonNull(svgParameters); + } + + @JsonCreator + public DiagramMetadata(@JsonProperty("layoutParameters") LayoutParameters layoutParameters, + @JsonProperty("svgParameters") SvgParameters svgParameters, + @JsonProperty("busNodes") List busNodesMetadata, + @JsonProperty("nodes") List nodesMetadata, + @JsonProperty("edges") List edgesMetadata, + @JsonProperty("textNodes") List textNodesMetadata) { + this.layoutParameters = Objects.requireNonNull(layoutParameters); + this.svgParameters = Objects.requireNonNull(svgParameters); + for (BusNodeMetadata busNodeMetadata : busNodesMetadata) { + this.busNodesMetadata.add(busNodeMetadata); + } + for (NodeMetadata nodeMetadata : nodesMetadata) { + this.nodesMetadata.add(nodeMetadata); } - if (layoutParametersMetadata != null) { - layoutParametersMetadata.write(writer); - } else { - LayoutParametersMetadata.writeEmpty(writer); + for (EdgeMetadata edgeMetadata : edgesMetadata) { + this.edgesMetadata.add(edgeMetadata); } - writer.writeEndElement(); - } - - private static void writeCollection( - Collection items, - String collectionElementName, - XMLStreamWriter writer) throws XMLStreamException { - if (items.isEmpty()) { - writer.writeEmptyElement(METADATA_PREFIX, collectionElementName, METADATA_NAMESPACE_URI); - } else { - writer.writeStartElement(METADATA_PREFIX, collectionElementName, METADATA_NAMESPACE_URI); - for (M item : items) { - item.write(writer); - } - writer.writeEndElement(); + for (TextNodeMetadata textNodeMetadata : textNodesMetadata) { + this.textNodesMetadata.add(textNodeMetadata); } } - public void addBusNode(String svgId, String equipmentId, String nbNeighbours, String index, String vlNodeId) { - busNodesMetadata.add(new BusNodeMetadata(svgId, equipmentId, nbNeighbours, index, vlNodeId)); + @JsonProperty("busNodes") + public List getBusNodesMetadata() { + return busNodesMetadata; } - public void addNode(String svgId, String equipmentId, String positionX, String positionY) { - nodesMetadata.add(new NodeMetadata(svgId, equipmentId, positionX, positionY)); + @JsonProperty("nodes") + public List getNodesMetadata() { + return nodesMetadata; } - public void addEdge(String svgId, String equipmentId, String node1SvgId, String node2SvgId, String busNode1SvgId, String busNode2SvgId, String edgeType) { - edgesMetadata.add(new EdgeMetadata(svgId, equipmentId, node1SvgId, node2SvgId, busNode1SvgId, busNode2SvgId, edgeType)); + @JsonProperty("edges") + public List getEdgesMetadata() { + return edgesMetadata; } - public void addTextNode(String svgId, String equipmentId, String vlNodeId, String positionShiftX, String positionShiftY, String connectionShiftX, String connectionShiftY) { - textNodesMetadata.add(new TextNodeMetadata(svgId, equipmentId, vlNodeId, positionShiftX, positionShiftY, connectionShiftX, connectionShiftY)); + @JsonProperty("textNodes") + public List getTextNodesMetadata() { + return textNodesMetadata; } - public void addSvgParameters(String insertNameDesc, String svgWidthAndHeightAdded, String cssLocation, String sizeConstraint, String fixedWidth, - String fixedHeight, String fixedScale, String arrowShift, String arrowLabelShift, String converterStationWidth, - String voltageLevelCircleRadius, String fictitiousVoltageLevelCircleRadius, String transformerCircleRadius, - String nodeHollowWidth, String edgesForkLength, String edgesForkAperture, String edgeStartShift, String unknownBusNodeExtraRadius, - String loopDistance, String loopEdgesAperture, String loopControlDistance, String edgeInfoAlongEdge, String edgeNameDisplayed, - String interAnnulusSpace, String svgPrefix, String idDisplayed, String substationDescriptionDisplayed, String arrowHeight, - String busLegend, String voltageLevelDetails, String languageTag, String voltageValuePrecision, String powerValuePrecision, - String angleValuePrecision, String currentValuePrecision, String edgeInfoDisplayed, String pstArrowHeadSize, String undefinedValueSymbol) { - svgParametersMetadata = new SvgParametersMetadata(insertNameDesc, svgWidthAndHeightAdded, cssLocation, sizeConstraint, fixedWidth, fixedHeight, fixedScale, - arrowShift, arrowLabelShift, converterStationWidth, voltageLevelCircleRadius, fictitiousVoltageLevelCircleRadius, - transformerCircleRadius, nodeHollowWidth, edgesForkLength, edgesForkAperture, edgeStartShift, - unknownBusNodeExtraRadius, loopDistance, loopEdgesAperture, loopControlDistance, edgeInfoAlongEdge, - edgeNameDisplayed, interAnnulusSpace, svgPrefix, idDisplayed, substationDescriptionDisplayed, arrowHeight, - busLegend, voltageLevelDetails, languageTag, voltageValuePrecision, powerValuePrecision, angleValuePrecision, - currentValuePrecision, edgeInfoDisplayed, pstArrowHeadSize, undefinedValueSymbol); + @JsonProperty("layoutParameters") + public LayoutParameters getLayoutParameters() { + return layoutParameters; } - public void addLayoutParameters(String textNodesForceLayout, String springRepulsionFactorForceLayout, String textNodeFixedShiftX, - String textNodeFixedShiftY, String maxSteps, String textNodeEdgeConnectionYShift) { - layoutParametersMetadata = new LayoutParametersMetadata(textNodesForceLayout, springRepulsionFactorForceLayout, textNodeFixedShiftX, - textNodeFixedShiftY, maxSteps, textNodeEdgeConnectionYShift); + @JsonProperty("svgParameters") + public SvgParameters getSvgParameters() { + return svgParameters; + } + + public DiagramMetadata addMetadata(Graph graph) { + graph.getVoltageLevelNodesStream().forEach(vlNode -> vlNode.getBusNodeStream().forEach(busNode -> busNodesMetadata.add(new BusNodeMetadata( + getPrefixedId(busNode.getDiagramId()), + busNode.getEquipmentId(), + busNode.getNbNeighbouringBusNodes(), + busNode.getRingIndex(), + getPrefixedId(vlNode.getDiagramId()))))); + graph.getNodesStream().forEach(node -> nodesMetadata.add(new NodeMetadata( + getPrefixedId(node.getDiagramId()), + node.getEquipmentId(), + round(node.getX()), + round(node.getY())))); + graph.getBranchEdgeStream().forEach(edge -> edgesMetadata.add(new EdgeMetadata( + getPrefixedId(edge.getDiagramId()), + edge.getEquipmentId(), + getPrefixedId(graph.getNode1(edge).getDiagramId()), + getPrefixedId(graph.getNode2(edge).getDiagramId()), + getPrefixedId(graph.getBusGraphNode1(edge).getDiagramId()), + getPrefixedId(graph.getBusGraphNode2(edge).getDiagramId()), + edge.getType()))); + graph.getThreeWtEdgesStream().forEach(edge -> edgesMetadata.add(new EdgeMetadata( + getPrefixedId(edge.getDiagramId()), + edge.getEquipmentId(), + getPrefixedId(graph.getNode1(edge).getDiagramId()), + getPrefixedId(graph.getNode2(edge).getDiagramId()), + getPrefixedId(graph.getBusGraphNode1(edge).getDiagramId()), + getPrefixedId(graph.getBusGraphNode2(edge).getDiagramId()), + edge.getType()))); + graph.getVoltageLevelTextPairs().forEach(textPair -> textNodesMetadata.add(new TextNodeMetadata( + getPrefixedId(textPair.getSecond().getDiagramId()), + textPair.getFirst().getEquipmentId(), + getPrefixedId(textPair.getFirst().getDiagramId()), + round(textPair.getSecond().getX() - textPair.getFirst().getX()), + round(textPair.getSecond().getY() - textPair.getFirst().getY()), + round(textPair.getSecond().getEdgeConnection().getX() - textPair.getFirst().getX()), + round(textPair.getSecond().getEdgeConnection().getY() - textPair.getFirst().getY())))); + return this; + } + + private String getPrefixedId(String id) { + return svgParameters.getSvgPrefix() + id; + } + + private double round(double number) { + return Math.round(number * 100.0) / 100.0; + } + + public static DiagramMetadata parseJson(Path file) { + try (Reader reader = Files.newBufferedReader(file)) { + return parseJson(reader); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public static DiagramMetadata parseJson(InputStream inputStream) { + Objects.requireNonNull(inputStream); + ObjectMapper objectMapper = JsonUtil.createObjectMapper(); + try { + return objectMapper.readValue(inputStream, DiagramMetadata.class); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public static DiagramMetadata parseJson(Reader reader) { + Objects.requireNonNull(reader); + ObjectMapper objectMapper = JsonUtil.createObjectMapper(); + try { + return objectMapper.readValue(reader, DiagramMetadata.class); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public void writeJson(Path file) { + Objects.requireNonNull(file); + try (Writer writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { + writeJson(writer); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public void writeJson(Writer writer) { + Objects.requireNonNull(writer); + ObjectMapper objectMapper = JsonUtil.createObjectMapper(); + try { + objectMapper.writerWithDefaultPrettyPrinter() + .writeValue(writer, this); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/EdgeMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/EdgeMetadata.java index e3e353a37..1876e9df7 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/EdgeMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/EdgeMetadata.java @@ -7,33 +7,28 @@ */ package com.powsybl.nad.svg.metadata; -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.xml.XmlUtil; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Luma Zamarreño {@literal } */ +@JsonInclude(JsonInclude.Include.NON_NULL) 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"; - private static final String BUS_NODE1_ATTRIBUTE = "busNode1"; - private static final String BUS_NODE2_ATTRIBUTE = "busNode2"; - private static final String EDGE_TYPE_ATTRIBUTE = "type"; - private final String node1SvgId; private final String node2SvgId; private final String busNode1SvgId; private final String busNode2SvgId; private final String edgeType; - public EdgeMetadata(String svgId, String equipmentId, String node1SvgId, String node2SvgId, - String busNode1SvgId, String busNode2SvgId, String edgeType) { + public EdgeMetadata(@JsonProperty("svgId") String svgId, + @JsonProperty("equipmentId") String equipmentId, + @JsonProperty("node1") String node1SvgId, + @JsonProperty("node2") String node2SvgId, + @JsonProperty("busNode1") String busNode1SvgId, + @JsonProperty("busNode2") String busNode2SvgId, + @JsonProperty("type") String edgeType) { super(svgId, equipmentId); this.node1SvgId = node1SvgId; this.node2SvgId = node2SvgId; @@ -42,41 +37,28 @@ public EdgeMetadata(String svgId, String equipmentId, String node1SvgId, String this.edgeType = edgeType; } - @Override - String getElementName() { - return ELEMENT_NAME; + @JsonProperty("node1") + public String getNode1SvgId() { + return node1SvgId; } - @Override - void write(XMLStreamWriter writer) throws XMLStreamException { - super.write(writer); - writer.writeAttribute(NODE1_ATTRIBUTE, node1SvgId); - writer.writeAttribute(NODE2_ATTRIBUTE, node2SvgId); - writer.writeAttribute(BUS_NODE1_ATTRIBUTE, busNode1SvgId); - writer.writeAttribute(BUS_NODE2_ATTRIBUTE, busNode2SvgId); - writer.writeAttribute(EDGE_TYPE_ATTRIBUTE, edgeType); + @JsonProperty("node2") + public String getNode2SvgId() { + return node2SvgId; } - static class Reader implements MetadataItemReader { - @Override - public String getElementName() { - return ELEMENT_NAME; - } + @JsonProperty("busNode1") + public String getBusNode1SvgId() { + return busNode1SvgId; + } + + @JsonProperty("busNode2") + public String getBusNode2SvgId() { + return busNode2SvgId; + } - public EdgeMetadata read(XMLStreamReader reader) { - try { - String svgId = readDiagramId(reader); - String equipmentId = readEquipmentId(reader); - String node1 = reader.getAttributeValue(null, NODE1_ATTRIBUTE); - String node2 = reader.getAttributeValue(null, NODE2_ATTRIBUTE); - String busNode1 = reader.getAttributeValue(null, BUS_NODE1_ATTRIBUTE); - String busNode2 = reader.getAttributeValue(null, BUS_NODE2_ATTRIBUTE); - String edgeType = reader.getAttributeValue(null, EDGE_TYPE_ATTRIBUTE); - XmlUtil.readEndElementOrThrow(reader); - return new EdgeMetadata(svgId, equipmentId, node1, node2, busNode1, busNode2, edgeType); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - } + @JsonProperty("type") + public String getEdgeType() { + return edgeType; } } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/LayoutParametersMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/LayoutParametersMetadata.java deleted file mode 100644 index 2f6906398..000000000 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/LayoutParametersMetadata.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright (c) 2024, RTE (http://www.rte-france.com/) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * SPDX-License-Identifier: MPL-2.0 - */ -package com.powsybl.nad.svg.metadata; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.xml.XmlUtil; - -/** - * @author Massimo Ferraro {@literal } - */ -public class LayoutParametersMetadata { - - private static final String ELEMENT_NAME = "layoutParameters"; - private static final String TEXT_NODES_FORCE_LAYOUT = "textNodesForceLayout"; - private static final String SPRING_REPULSION_FACTOR_FORCE_LAYOUT = "springRepulsionFactorForceLayout"; - private static final String TEXT_NODE_FIXED_SHIFT_X = "textNodeFixedShiftX"; - private static final String TEXT_NODE_FIXED_SHIFT_Y = "textNodeFixedShiftY"; - private static final String MAX_STEPS = "maxSteps"; - private static final String TEXT_NODE_EDGE_CONNECTION_Y_SHIFT = "textNodeEdgeConnectionYShift"; - - private final String textNodesForceLayout; - private final String springRepulsionFactorForceLayout; - private final String textNodeFixedShiftX; - private final String textNodeFixedShiftY; - private final String maxSteps; - private final String textNodeEdgeConnectionYShift; - - public LayoutParametersMetadata(String textNodesForceLayout, String springRepulsionFactorForceLayout, String textNodeFixedShiftX, - String textNodeFixedShiftY, String maxSteps, String textNodeEdgeConnectionYShift) { - this.textNodesForceLayout = textNodesForceLayout; - this.springRepulsionFactorForceLayout = springRepulsionFactorForceLayout; - this.textNodeFixedShiftX = textNodeFixedShiftX; - this.textNodeFixedShiftY = textNodeFixedShiftY; - this.maxSteps = maxSteps; - this.textNodeEdgeConnectionYShift = textNodeEdgeConnectionYShift; - } - - String getElementName() { - return ELEMENT_NAME; - } - - void write(XMLStreamWriter writer) throws XMLStreamException { - writer.writeEmptyElement(DiagramMetadata.METADATA_PREFIX, getElementName(), DiagramMetadata.METADATA_NAMESPACE_URI); - writer.writeAttribute(TEXT_NODES_FORCE_LAYOUT, textNodesForceLayout); - writer.writeAttribute(SPRING_REPULSION_FACTOR_FORCE_LAYOUT, springRepulsionFactorForceLayout); - writer.writeAttribute(TEXT_NODE_FIXED_SHIFT_X, textNodeFixedShiftX); - writer.writeAttribute(TEXT_NODE_FIXED_SHIFT_Y, textNodeFixedShiftY); - writer.writeAttribute(MAX_STEPS, maxSteps); - writer.writeAttribute(TEXT_NODE_EDGE_CONNECTION_Y_SHIFT, textNodeEdgeConnectionYShift); - } - - static void writeEmpty(XMLStreamWriter writer) throws XMLStreamException { - writer.writeEmptyElement(DiagramMetadata.METADATA_PREFIX, ELEMENT_NAME, DiagramMetadata.METADATA_NAMESPACE_URI); - } - - static class Reader { - - private final String elementName; - - Reader() { - this.elementName = ELEMENT_NAME; - } - - public String getElementName() { - return elementName; - } - - public LayoutParametersMetadata read(XMLStreamReader reader) { - try { - String textNodesForceLayout = reader.getAttributeValue(null, TEXT_NODES_FORCE_LAYOUT); - String springRepulsionFactorForceLayout = reader.getAttributeValue(null, SPRING_REPULSION_FACTOR_FORCE_LAYOUT); - String textNodeFixedShiftX = reader.getAttributeValue(null, TEXT_NODE_FIXED_SHIFT_X); - String textNodeFixedShiftY = reader.getAttributeValue(null, TEXT_NODE_FIXED_SHIFT_Y); - String maxSteps = reader.getAttributeValue(null, MAX_STEPS); - String textNodeEdgeConnectionYShift = reader.getAttributeValue(null, TEXT_NODE_EDGE_CONNECTION_Y_SHIFT); - XmlUtil.readEndElementOrThrow(reader); - return new LayoutParametersMetadata(textNodesForceLayout, springRepulsionFactorForceLayout, textNodeFixedShiftX, - textNodeFixedShiftY, maxSteps, textNodeEdgeConnectionYShift); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - } - } -} diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java index 167de08b8..b61095e03 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java @@ -7,66 +7,34 @@ */ package com.powsybl.nad.svg.metadata; -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.xml.XmlUtil; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Luma Zamarreño {@literal } */ +@JsonInclude(JsonInclude.Include.NON_NULL) public class NodeMetadata extends AbstractMetadataItem { - private static final String ELEMENT_NAME = "node"; - private static final String POSITION_X_ATTRIBUTE = "x"; - private static final String POSITION_Y_ATTRIBUTE = "y"; - private final String positionX; - private final String positionY; + private final double positionX; + private final double positionY; - public NodeMetadata(String svgId, String equipmentId, String positionX, String positionY) { + public NodeMetadata(@JsonProperty("svgId") String svgId, + @JsonProperty("equipmentId") String equipmentId, + @JsonProperty("x") double positionX, + @JsonProperty("y") double positionY) { super(svgId, equipmentId); this.positionX = positionX; this.positionY = positionY; } - @Override - String getElementName() { - return ELEMENT_NAME; - } - - @Override - void write(XMLStreamWriter writer) throws XMLStreamException { - super.write(writer); - writer.writeAttribute(POSITION_X_ATTRIBUTE, positionX); - writer.writeAttribute(POSITION_Y_ATTRIBUTE, positionY); + @JsonProperty("x") + public double getPositionX() { + return positionX; } - static class Reader implements MetadataItemReader { - - private final String elementName; - - Reader() { - this.elementName = ELEMENT_NAME; - } - - @Override - public String getElementName() { - return elementName; - } - - public NodeMetadata read(XMLStreamReader reader) { - try { - String diagramId = readDiagramId(reader); - String equipmentId = readEquipmentId(reader); - String positionX = reader.getAttributeValue(null, POSITION_X_ATTRIBUTE); - String positionY = reader.getAttributeValue(null, POSITION_Y_ATTRIBUTE); - XmlUtil.readEndElementOrThrow(reader); - return new NodeMetadata(diagramId, equipmentId, positionX, positionY); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - } + @JsonProperty("y") + public double getPositionY() { + return positionY; } } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/SvgParametersMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/SvgParametersMetadata.java deleted file mode 100644 index 430557427..000000000 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/SvgParametersMetadata.java +++ /dev/null @@ -1,269 +0,0 @@ -/** - * Copyright (c) 2024, RTE (http://www.rte-france.com/) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * SPDX-License-Identifier: MPL-2.0 - */ -package com.powsybl.nad.svg.metadata; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.xml.XmlUtil; - -/** - * @author Massimo Ferraro {@literal } - */ -public class SvgParametersMetadata { - - private static final String ELEMENT_NAME = "svgParameters"; - private static final String INSERT_NAME_DESC = "insertNameDesc"; - private static final String SVG_WIDTH_AND_HEIGHT_ADDED = "svgWidthAndHeightAdded"; - private static final String CSS_LOCATION = "cssLocation"; - private static final String SIZE_CONSTRAINT = "sizeConstraint"; - private static final String FIXED_WIDTH = "fixedWidth"; - private static final String FIXED_HEIGHT = "fixedHeight"; - private static final String FIXED_SCALE = "fixedScale"; - private static final String ARROW_SHIFT = "arrowShift"; - private static final String ARROW_LABEL_SHIFT = "arrowLabelShift"; - private static final String CONVERTER_STATION_WIDTH = "converterStationWidth"; - private static final String VOLTAGE_LEVEL_CIRCLE_RADIUS = "voltageLevelCircleRadius"; - private static final String FICTITIOUS_VOLTAGE_LEVEL_CIRCLE_RADIUS = "fictitiousVoltageLevelCircleRadius"; - private static final String TRANSFORMER_CIRCLE_RADIUS = "transformerCircleRadius"; - private static final String NODE_HOLLOW_WIDTH = "nodeHollowWidth"; - private static final String EDGES_FORK_LENGTH = "edgesForkLength"; - private static final String EDGES_FORK_APERTURE = "edgesForkAperture"; - private static final String EDGE_START_SHIFT = "edgeStartShift"; - private static final String UNKNOWN_BUS_NODE_EXTRA_RADIUS = "unknownBusNodeExtraRadius"; - private static final String LOOP_DISTANCE = "loopDistance"; - private static final String LOOP_EDGES_APERTURE = "loopEdgesAperture"; - private static final String LOOP_CONTROL_DISTANCE = "loopControlDistance"; - private static final String EDGE_INFO_ALONG_EDGE = "edgeInfoAlongEdge"; - private static final String EDGE_NAME_DISPLAYED = "edgeNameDisplayed"; - private static final String INTER_ANNULUS_SPACE = "interAnnulusSpace"; - private static final String SVG_PREFIX = "svgPrefix"; - private static final String ID_DISPLAYED = "idDisplayed"; - private static final String SUBSTATION_DESCRIPTION_DISPLAYED = "substationDescriptionDisplayed"; - private static final String ARROW_HEIGHT = "arrowHeight"; - private static final String BUS_LEGEND = "busLegend"; - private static final String VOLTAGE_LEVEL_DETAILS = "voltageLevelDetails"; - private static final String LANGUAGE_TAG = "languageTag"; - private static final String VOLTAGE_VALUE_PRECISION = "voltageValuePrecision"; - private static final String POWER_VALUE_PRECISION = "powerValuePrecision"; - private static final String ANGLE_VALUE_PRECISION = "angleValuePrecision"; - private static final String CURRENT_VALUE_PRECISION = "currentValuePrecision"; - private static final String EDGE_INFO_DISPLAYED = "edgeInfoDisplayed"; - private static final String PST_ARROW_HEAD_SIZE = "pstArrowHeadSize"; - private static final String UNDEFINED_VALUE_SYMBOL = "undefinedValueSymbol"; - - private final String insertNameDesc; - private final String svgWidthAndHeightAdded; - private final String cssLocation; - private final String sizeConstraint; - private final String fixedWidth; - private final String fixedHeight; - private final String fixedScale; - private final String arrowShift; - private final String arrowLabelShift; - private final String converterStationWidth; - private final String voltageLevelCircleRadius; - private final String fictitiousVoltageLevelCircleRadius; - private final String transformerCircleRadius; - private final String nodeHollowWidth; - private final String edgesForkLength; - private final String edgesForkAperture; - private final String edgeStartShift; - private final String unknownBusNodeExtraRadius; - private final String loopDistance; - private final String loopEdgesAperture; - private final String loopControlDistance; - private final String edgeInfoAlongEdge; - private final String edgeNameDisplayed; - private final String interAnnulusSpace; - private final String svgPrefix; - private final String idDisplayed; - private final String substationDescriptionDisplayed; - private final String arrowHeight; - private final String busLegend; - private final String voltageLevelDetails; - private final String languageTag; - private final String voltageValuePrecision; - private final String powerValuePrecision; - private final String angleValuePrecision; - private final String currentValuePrecision; - private final String edgeInfoDisplayed; - private final String pstArrowHeadSize; - private final String undefinedValueSymbol; - - public SvgParametersMetadata(String insertNameDesc, String svgWidthAndHeightAdded, String cssLocation, - String sizeConstraint, String fixedWidth, String fixedHeight, String fixedScale, - String arrowShift, String arrowLabelShift, String converterStationWidth, - String voltageLevelCircleRadius, String fictitiousVoltageLevelCircleRadius, - String transformerCircleRadius, String nodeHollowWidth, String edgesForkLength, - String edgesForkAperture, String edgeStartShift, String unknownBusNodeExtraRadius, - String loopDistance, String loopEdgesAperture, String loopControlDistance, - String edgeInfoAlongEdge, String edgeNameDisplayed, String interAnnulusSpace, - String svgPrefix, String idDisplayed, String substationDescriptionDisplayed, - String arrowHeight, String busLegend, String voltageLevelDetails, - String languageTag, String voltageValuePrecision, String powerValuePrecision, - String angleValuePrecision, String currentValuePrecision, String edgeInfoDisplayed, - String pstArrowHeadSize, String undefinedValueSymbol) { - this.insertNameDesc = insertNameDesc; - this.svgWidthAndHeightAdded = svgWidthAndHeightAdded; - this.cssLocation = cssLocation; - this.sizeConstraint = sizeConstraint; - this.fixedWidth = fixedWidth; - this.fixedHeight = fixedHeight; - this.fixedScale = fixedScale; - this.arrowShift = arrowShift; - this.arrowLabelShift = arrowLabelShift; - this.converterStationWidth = converterStationWidth; - this.voltageLevelCircleRadius = voltageLevelCircleRadius; - this.fictitiousVoltageLevelCircleRadius = fictitiousVoltageLevelCircleRadius; - this.transformerCircleRadius = transformerCircleRadius; - this.nodeHollowWidth = nodeHollowWidth; - this.edgesForkLength = edgesForkLength; - this.edgesForkAperture = edgesForkAperture; - this.edgeStartShift = edgeStartShift; - this.unknownBusNodeExtraRadius = unknownBusNodeExtraRadius; - this.loopDistance = loopDistance; - this.loopEdgesAperture = loopEdgesAperture; - this.loopControlDistance = loopControlDistance; - this.edgeInfoAlongEdge = edgeInfoAlongEdge; - this.edgeNameDisplayed = edgeNameDisplayed; - this.interAnnulusSpace = interAnnulusSpace; - this.svgPrefix = svgPrefix; - this.idDisplayed = idDisplayed; - this.substationDescriptionDisplayed = substationDescriptionDisplayed; - this.arrowHeight = arrowHeight; - this.busLegend = busLegend; - this.voltageLevelDetails = voltageLevelDetails; - this.languageTag = languageTag; - this.voltageValuePrecision = voltageValuePrecision; - this.powerValuePrecision = powerValuePrecision; - this.angleValuePrecision = angleValuePrecision; - this.currentValuePrecision = currentValuePrecision; - this.edgeInfoDisplayed = edgeInfoDisplayed; - this.pstArrowHeadSize = pstArrowHeadSize; - this.undefinedValueSymbol = undefinedValueSymbol; - } - - String getElementName() { - return ELEMENT_NAME; - } - - void write(XMLStreamWriter writer) throws XMLStreamException { - writer.writeEmptyElement(DiagramMetadata.METADATA_PREFIX, getElementName(), DiagramMetadata.METADATA_NAMESPACE_URI); - writer.writeAttribute(INSERT_NAME_DESC, insertNameDesc); - writer.writeAttribute(SVG_WIDTH_AND_HEIGHT_ADDED, svgWidthAndHeightAdded); - writer.writeAttribute(CSS_LOCATION, cssLocation); - writer.writeAttribute(SIZE_CONSTRAINT, sizeConstraint); - writer.writeAttribute(FIXED_WIDTH, fixedWidth); - writer.writeAttribute(FIXED_HEIGHT, fixedHeight); - writer.writeAttribute(FIXED_SCALE, fixedScale); - writer.writeAttribute(ARROW_SHIFT, arrowShift); - writer.writeAttribute(ARROW_LABEL_SHIFT, arrowLabelShift); - writer.writeAttribute(CONVERTER_STATION_WIDTH, converterStationWidth); - writer.writeAttribute(VOLTAGE_LEVEL_CIRCLE_RADIUS, voltageLevelCircleRadius); - writer.writeAttribute(FICTITIOUS_VOLTAGE_LEVEL_CIRCLE_RADIUS, fictitiousVoltageLevelCircleRadius); - writer.writeAttribute(TRANSFORMER_CIRCLE_RADIUS, transformerCircleRadius); - writer.writeAttribute(NODE_HOLLOW_WIDTH, nodeHollowWidth); - writer.writeAttribute(EDGES_FORK_LENGTH, edgesForkLength); - writer.writeAttribute(EDGES_FORK_APERTURE, edgesForkAperture); - writer.writeAttribute(EDGE_START_SHIFT, edgeStartShift); - writer.writeAttribute(UNKNOWN_BUS_NODE_EXTRA_RADIUS, unknownBusNodeExtraRadius); - writer.writeAttribute(LOOP_DISTANCE, loopDistance); - writer.writeAttribute(LOOP_EDGES_APERTURE, loopEdgesAperture); - writer.writeAttribute(LOOP_CONTROL_DISTANCE, loopControlDistance); - writer.writeAttribute(EDGE_INFO_ALONG_EDGE, edgeInfoAlongEdge); - writer.writeAttribute(EDGE_NAME_DISPLAYED, edgeNameDisplayed); - writer.writeAttribute(INTER_ANNULUS_SPACE, interAnnulusSpace); - writer.writeAttribute(SVG_PREFIX, svgPrefix); - writer.writeAttribute(ID_DISPLAYED, idDisplayed); - writer.writeAttribute(SUBSTATION_DESCRIPTION_DISPLAYED, substationDescriptionDisplayed); - writer.writeAttribute(ARROW_HEIGHT, arrowHeight); - writer.writeAttribute(BUS_LEGEND, busLegend); - writer.writeAttribute(VOLTAGE_LEVEL_DETAILS, voltageLevelDetails); - writer.writeAttribute(LANGUAGE_TAG, languageTag); - writer.writeAttribute(VOLTAGE_VALUE_PRECISION, voltageValuePrecision); - writer.writeAttribute(POWER_VALUE_PRECISION, powerValuePrecision); - writer.writeAttribute(ANGLE_VALUE_PRECISION, angleValuePrecision); - writer.writeAttribute(CURRENT_VALUE_PRECISION, currentValuePrecision); - writer.writeAttribute(EDGE_INFO_DISPLAYED, edgeInfoDisplayed); - writer.writeAttribute(PST_ARROW_HEAD_SIZE, pstArrowHeadSize); - writer.writeAttribute(UNDEFINED_VALUE_SYMBOL, undefinedValueSymbol); - } - - static void writeEmpty(XMLStreamWriter writer) throws XMLStreamException { - writer.writeEmptyElement(DiagramMetadata.METADATA_PREFIX, ELEMENT_NAME, DiagramMetadata.METADATA_NAMESPACE_URI); - } - - static class Reader { - - private final String elementName; - - Reader() { - this.elementName = ELEMENT_NAME; - } - - public String getElementName() { - return elementName; - } - - public SvgParametersMetadata read(XMLStreamReader reader) { - try { - String insertNameDesc = reader.getAttributeValue(null, INSERT_NAME_DESC); - String svgWidthAndHeightAdded = reader.getAttributeValue(null, SVG_WIDTH_AND_HEIGHT_ADDED); - String cssLocation = reader.getAttributeValue(null, CSS_LOCATION); - String sizeConstraint = reader.getAttributeValue(null, SIZE_CONSTRAINT); - String fixedWidth = reader.getAttributeValue(null, FIXED_WIDTH); - String fixedHeight = reader.getAttributeValue(null, FIXED_HEIGHT); - String fixedScale = reader.getAttributeValue(null, FIXED_SCALE); - String arrowShift = reader.getAttributeValue(null, ARROW_SHIFT); - String arrowLabelShift = reader.getAttributeValue(null, ARROW_LABEL_SHIFT); - String converterStationWidth = reader.getAttributeValue(null, CONVERTER_STATION_WIDTH); - String voltageLevelCircleRadius = reader.getAttributeValue(null, VOLTAGE_LEVEL_CIRCLE_RADIUS); - String fictitiousVoltageLevelCircleRadius = reader.getAttributeValue(null, FICTITIOUS_VOLTAGE_LEVEL_CIRCLE_RADIUS); - String transformerCircleRadius = reader.getAttributeValue(null, TRANSFORMER_CIRCLE_RADIUS); - String nodeHollowWidth = reader.getAttributeValue(null, NODE_HOLLOW_WIDTH); - String edgesForkLength = reader.getAttributeValue(null, EDGES_FORK_LENGTH); - String edgesForkAperture = reader.getAttributeValue(null, EDGES_FORK_APERTURE); - String edgeStartShift = reader.getAttributeValue(null, EDGE_START_SHIFT); - String unknownBusNodeExtraRadius = reader.getAttributeValue(null, UNKNOWN_BUS_NODE_EXTRA_RADIUS); - String loopDistance = reader.getAttributeValue(null, LOOP_DISTANCE); - String loopEdgesAperture = reader.getAttributeValue(null, LOOP_EDGES_APERTURE); - String loopControlDistance = reader.getAttributeValue(null, LOOP_CONTROL_DISTANCE); - String edgeInfoAlongEdge = reader.getAttributeValue(null, EDGE_INFO_ALONG_EDGE); - String edgeNameDisplayed = reader.getAttributeValue(null, EDGE_NAME_DISPLAYED); - String interAnnulusSpace = reader.getAttributeValue(null, INTER_ANNULUS_SPACE); - String svgPrefix = reader.getAttributeValue(null, SVG_PREFIX); - String idDisplayed = reader.getAttributeValue(null, ID_DISPLAYED); - String substationDescriptionDisplayed = reader.getAttributeValue(null, SUBSTATION_DESCRIPTION_DISPLAYED); - String arrowHeight = reader.getAttributeValue(null, ARROW_HEIGHT); - String busLegend = reader.getAttributeValue(null, BUS_LEGEND); - String voltageLevelDetails = reader.getAttributeValue(null, VOLTAGE_LEVEL_DETAILS); - String languageTag = reader.getAttributeValue(null, LANGUAGE_TAG); - String voltageValuePrecision = reader.getAttributeValue(null, VOLTAGE_VALUE_PRECISION); - String powerValuePrecision = reader.getAttributeValue(null, POWER_VALUE_PRECISION); - String angleValuePrecision = reader.getAttributeValue(null, ANGLE_VALUE_PRECISION); - String currentValuePrecision = reader.getAttributeValue(null, CURRENT_VALUE_PRECISION); - String edgeInfoDisplayed = reader.getAttributeValue(null, EDGE_INFO_DISPLAYED); - String pstArrowHeadSize = reader.getAttributeValue(null, PST_ARROW_HEAD_SIZE); - String undefinedValueSymbol = reader.getAttributeValue(null, UNDEFINED_VALUE_SYMBOL); - XmlUtil.readEndElementOrThrow(reader); - return new SvgParametersMetadata(insertNameDesc, svgWidthAndHeightAdded, cssLocation, sizeConstraint, fixedWidth, fixedHeight, fixedScale, - arrowShift, arrowLabelShift, converterStationWidth, voltageLevelCircleRadius, fictitiousVoltageLevelCircleRadius, - transformerCircleRadius, nodeHollowWidth, edgesForkLength, edgesForkAperture, edgeStartShift, - unknownBusNodeExtraRadius, loopDistance, loopEdgesAperture, loopControlDistance, edgeInfoAlongEdge, - edgeNameDisplayed, interAnnulusSpace, svgPrefix, idDisplayed, substationDescriptionDisplayed, arrowHeight, - busLegend, voltageLevelDetails, languageTag, voltageValuePrecision, powerValuePrecision, angleValuePrecision, - currentValuePrecision, edgeInfoDisplayed, pstArrowHeadSize, undefinedValueSymbol); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - } - } -} diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java index c9ac4dcae..94c830199 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java @@ -7,33 +7,28 @@ */ package com.powsybl.nad.svg.metadata; -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.xml.XmlUtil; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Massimo Ferraro {@literal } */ - +@JsonInclude(JsonInclude.Include.NON_NULL) public class TextNodeMetadata extends AbstractMetadataItem { - private static final String ELEMENT_NAME = "textNode"; - private static final String VL_NODE_ATTRIBUTE = "vlNode"; - private static final String POSITION_SHIFT_X_ATTRIBUTE = "shiftX"; - private static final String POSITION_SHIFT_Y_ATTRIBUTE = "shiftY"; - private static final String CONNECTION_SHIFT_X_ATTRIBUTE = "connectionShiftX"; - private static final String CONNECTION_SHIFT_Y_ATTRIBUTE = "connectionShiftY"; private final String vlNodeId; - private final String positionShiftX; - private final String positionShiftY; - private final String connectionShiftX; - private final String connectionShiftY; + private final double positionShiftX; + private final double positionShiftY; + private final double connectionShiftX; + private final double connectionShiftY; - public TextNodeMetadata(String svgId, String equipmentId, String vlNodeId, String positionShiftX, String positionShiftY, - String connectionShiftX, String connectionShiftY) { + public TextNodeMetadata(@JsonProperty("svgId") String svgId, + @JsonProperty("equipmentId") String equipmentId, + @JsonProperty("vlNode") String vlNodeId, + @JsonProperty("shiftX") double positionShiftX, + @JsonProperty("shiftY") double positionShiftY, + @JsonProperty("connectionShiftX") double connectionShiftX, + @JsonProperty("connectionShiftY") double connectionShiftY) { super(svgId, equipmentId); this.vlNodeId = vlNodeId; this.positionShiftX = positionShiftX; @@ -42,41 +37,28 @@ public TextNodeMetadata(String svgId, String equipmentId, String vlNodeId, Strin this.connectionShiftY = connectionShiftY; } - @Override - String getElementName() { - return ELEMENT_NAME; + @JsonProperty("vlNode") + public String getVlNodeId() { + return vlNodeId; } - @Override - void write(XMLStreamWriter writer) throws XMLStreamException { - super.write(writer); - writer.writeAttribute(VL_NODE_ATTRIBUTE, vlNodeId); - writer.writeAttribute(POSITION_SHIFT_X_ATTRIBUTE, positionShiftX); - writer.writeAttribute(POSITION_SHIFT_Y_ATTRIBUTE, positionShiftY); - writer.writeAttribute(CONNECTION_SHIFT_X_ATTRIBUTE, connectionShiftX); - writer.writeAttribute(CONNECTION_SHIFT_Y_ATTRIBUTE, connectionShiftY); + @JsonProperty("shiftX") + public double getPositionShiftX() { + return positionShiftX; } - static class Reader implements AbstractMetadataItem.MetadataItemReader { - @Override - public String getElementName() { - return ELEMENT_NAME; - } + @JsonProperty("shiftY") + public double getPositionShiftY() { + return positionShiftY; + } + + @JsonProperty("connectionShiftX") + public double getConnectionShiftX() { + return connectionShiftX; + } - public TextNodeMetadata read(XMLStreamReader reader) { - try { - String diagramId = readDiagramId(reader); - String equipmentId = readEquipmentId(reader); - String vlNodeId = reader.getAttributeValue(null, VL_NODE_ATTRIBUTE); - String positionShiftX = reader.getAttributeValue(null, POSITION_SHIFT_X_ATTRIBUTE); - String positionShiftY = reader.getAttributeValue(null, POSITION_SHIFT_Y_ATTRIBUTE); - String connectionShiftX = reader.getAttributeValue(null, CONNECTION_SHIFT_X_ATTRIBUTE); - String connectionShiftY = reader.getAttributeValue(null, CONNECTION_SHIFT_Y_ATTRIBUTE); - XmlUtil.readEndElementOrThrow(reader); - return new TextNodeMetadata(diagramId, equipmentId, vlNodeId, positionShiftX, positionShiftY, connectionShiftX, connectionShiftY); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - } + @JsonProperty("connectionShiftY") + public double getConnectionShiftY() { + return connectionShiftY; } } diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java index 1979332db..d1e225f94 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutWithInitialPositionsTest.java @@ -157,7 +157,8 @@ private Map layoutResult(Network network, nodesWithFixedPositions, fixedNodePositions); StringWriter writer = new StringWriter(); - NetworkAreaDiagram.draw(network, writer, + StringWriter metadataWriter = new StringWriter(); + NetworkAreaDiagram.draw(network, writer, metadataWriter, new NadParameters() .setSvgParameters(getSvgParameters()) .setLayoutParameters(getLayoutParameters()) diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java index 098ba34cc..fd8dc6176 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java @@ -9,10 +9,14 @@ import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; -import com.powsybl.commons.xml.XmlUtil; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory; import com.powsybl.nad.AbstractTest; +import com.powsybl.nad.build.iidm.NetworkGraphBuilder; +import com.powsybl.nad.build.iidm.VoltageLevelFilter; +import com.powsybl.nad.layout.BasicForceLayout; import com.powsybl.nad.layout.LayoutParameters; +import com.powsybl.nad.model.Graph; import com.powsybl.nad.svg.iidm.DefaultLabelProvider; import com.powsybl.nad.svg.iidm.TopologicalStyleProvider; import com.powsybl.nad.svg.metadata.DiagramMetadata; @@ -21,8 +25,6 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; @@ -35,11 +37,6 @@ */ class DiagramMetadataTest extends AbstractTest { - private static final String INDENT = " "; - private static final String METADATA = "metadata"; - private static final String METADATA_START_TOKEN = "<" + METADATA + ">"; - private static final String METADATA_END_TOKEN = ""; - private FileSystem fileSystem; private Path tmpDir; @@ -70,91 +67,47 @@ protected LabelProvider getLabelProvider(Network network) { } @Test - void test() throws XMLStreamException { - // Referenced svg file - String reference = "/hvdc.svg"; + void test() { + // Referenced json file + String reference = "/hvdc_metadata.json"; InputStream in = Objects.requireNonNull(getClass().getResourceAsStream(reference)); - // Create Metadata from svg file - DiagramMetadata metadata = DiagramMetadata.readFromSvg(in); - // Write Metadata as temporary xml file - Path outPath = tmpDir.resolve("metadata.xml"); + // Create Metadata from json file + DiagramMetadata metadata = DiagramMetadata.parseJson(in); + // Write Metadata as temporary json file + Path outPath = tmpDir.resolve("metadata.json"); writeMetadata(metadata, outPath); - // Read xml file - String actual = toString(outPath); - // remove xml header (first line) - actual = actual.substring(actual.indexOf(METADATA_START_TOKEN)); - // Keep only metadata from svg file + // Read generated json file + String actual = getContentFile(outPath); + // Read reference json file String expected = toString(reference); - expected = expected.substring(expected.indexOf(METADATA_START_TOKEN), expected.indexOf(METADATA_END_TOKEN) + METADATA_END_TOKEN.length()); // Checking - assertEquals(removeWhiteSpaces(expected), removeWhiteSpaces(actual)); + assertEquals(expected, actual); } @Test - void testInvalid() throws XMLStreamException { - // Referenced svg file - String reference = """ - - - - - - - - - - - - """; - InputStream in = new ByteArrayInputStream(reference.getBytes(StandardCharsets.UTF_8)); - // Create Metadata from svg file - DiagramMetadata metadata = DiagramMetadata.readFromSvg(in); - // Write Metadata as temporary xml file - Path outPath = tmpDir.resolve("metadataInvalid.xml"); - writeMetadata(metadata, outPath); - // Read xml file - String actual = toString(outPath); - // remove xml header (first line) - actual = actual.substring(actual.indexOf(METADATA_START_TOKEN)); - // Keep only metadata from svg file - String expected = """ - - - - - - - - - - """; + void test3wt() { + // Referenced json file + String reference = "/3wt_metadata.json"; + // Write Metadata as temporary json file + Network network = ThreeWindingsTransformerNetworkFactory.create(); + Graph graph = new NetworkGraphBuilder(network, VoltageLevelFilter.NO_FILTER).buildGraph(); + new BasicForceLayout().run(graph, getLayoutParameters()); + Path outPath = tmpDir.resolve("metadata.json"); + new DiagramMetadata(getLayoutParameters(), getSvgParameters()).addMetadata(graph).writeJson(outPath); + // Read generated json file + String actual = getContentFile(outPath); + // Read reference json file + String expected = toString(reference); // Checking - assertEquals(removeWhiteSpaces(expected), removeWhiteSpaces(actual)); - } - - private void writeMetadata(DiagramMetadata metadata, Path outPath) throws XMLStreamException { - try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(outPath))) { - XMLStreamWriter writer = XmlUtil.initializeWriter(true, INDENT, os); - writer.writeStartElement(METADATA); - metadata.writeXml(writer); - writer.writeEndElement(); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + assertEquals(expected, actual); } - private String toString(Path outPath) { - String content; + private void writeMetadata(DiagramMetadata metadata, Path outPath) { try { - byte[] encoded = Files.readAllBytes(outPath); - content = new String(encoded, StandardCharsets.UTF_8); + Writer writer = Files.newBufferedWriter(outPath, StandardCharsets.UTF_8); + metadata.writeJson(writer); } catch (IOException e) { throw new UncheckedIOException(e); } - return content; - } - - private String removeWhiteSpaces(String input) { - return input.replaceAll("\\s+", ""); } } diff --git a/network-area-diagram/src/test/resources/3wt.svg b/network-area-diagram/src/test/resources/3wt.svg index 5febd5de0..92565a226 100644 --- a/network-area-diagram/src/test/resources/3wt.svg +++ b/network-area-diagram/src/test/resources/3wt.svg @@ -44,33 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - VL_11 diff --git a/network-area-diagram/src/test/resources/3wt_disconnected.svg b/network-area-diagram/src/test/resources/3wt_disconnected.svg index 5457ce45d..ff2b29f45 100644 --- a/network-area-diagram/src/test/resources/3wt_disconnected.svg +++ b/network-area-diagram/src/test/resources/3wt_disconnected.svg @@ -44,32 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - VL_11 diff --git a/network-area-diagram/src/test/resources/3wt_disconnected_topological.svg b/network-area-diagram/src/test/resources/3wt_disconnected_topological.svg index 067fd0ce3..04d96cd66 100644 --- a/network-area-diagram/src/test/resources/3wt_disconnected_topological.svg +++ b/network-area-diagram/src/test/resources/3wt_disconnected_topological.svg @@ -109,32 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - VL_11 diff --git a/network-area-diagram/src/test/resources/3wt_metadata.json b/network-area-diagram/src/test/resources/3wt_metadata.json new file mode 100644 index 000000000..2265c7af7 --- /dev/null +++ b/network-area-diagram/src/test/resources/3wt_metadata.json @@ -0,0 +1,148 @@ +{ + "layoutParameters" : { + "textNodesForceLayout" : false, + "springRepulsionFactorForceLayout" : 0.0, + "textNodeFixedShift" : { + "x" : 100.0, + "y" : -40.0 + }, + "maxSteps" : 1000, + "textNodeEdgeConnectionYShift" : 25.0 + }, + "svgParameters" : { + "diagramPadding" : { + "left" : 200.0, + "top" : 200.0, + "right" : 200.0, + "bottom" : 200.0 + }, + "insertNameDesc" : true, + "svgWidthAndHeightAdded" : true, + "cssLocation" : "INSERTED_IN_SVG", + "sizeConstraint" : "FIXED_WIDTH", + "fixedWidth" : 800, + "fixedHeight" : -1, + "fixedScale" : 0.2, + "arrowShift" : 30.0, + "arrowLabelShift" : 19.0, + "converterStationWidth" : 70.0, + "voltageLevelCircleRadius" : 30.0, + "fictitiousVoltageLevelCircleRadius" : 15.0, + "transformerCircleRadius" : 20.0, + "nodeHollowWidth" : 15.0, + "edgesForkLength" : 80.0, + "edgesForkAperture" : 60.0, + "edgeStartShift" : 0.0, + "unknownBusNodeExtraRadius" : 10.0, + "loopDistance" : 120.0, + "loopEdgesAperture" : 60.0, + "loopControlDistance" : 40.0, + "edgeInfoAlongEdge" : true, + "edgeNameDisplayed" : false, + "interAnnulusSpace" : 5.0, + "svgPrefix" : "", + "idDisplayed" : false, + "substationDescriptionDisplayed" : false, + "arrowHeight" : 10.0, + "busLegend" : true, + "voltageLevelDetails" : false, + "languageTag" : "en", + "voltageValuePrecision" : 1, + "powerValuePrecision" : 0, + "angleValuePrecision" : 1, + "currentValuePrecision" : 0, + "edgeInfoDisplayed" : "ACTIVE_POWER", + "pstArrowHeadSize" : 8.0, + "undefinedValueSymbol" : "" + }, + "busNodes" : [ { + "svgId" : "1", + "equipmentId" : "VL_11_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "0" + }, { + "svgId" : "3", + "equipmentId" : "VL_132_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "2" + }, { + "svgId" : "5", + "equipmentId" : "VL_33_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "4" + } ], + "nodes" : [ { + "svgId" : "0", + "equipmentId" : "VL_11", + "x" : 75.04, + "y" : -513.76 + }, { + "svgId" : "2", + "equipmentId" : "VL_132", + "x" : -371.52, + "y" : 47.69 + }, { + "svgId" : "4", + "equipmentId" : "VL_33", + "x" : 180.23, + "y" : 204.68 + }, { + "svgId" : "6", + "equipmentId" : "3WT", + "x" : -22.79, + "y" : -128.62 + } ], + "edges" : [ { + "svgId" : "7", + "equipmentId" : "3WT", + "node1" : "0", + "node2" : "6", + "busNode1" : "1", + "busNode2" : "6", + "type" : "ThreeWtEdge" + }, { + "svgId" : "8", + "equipmentId" : "3WT", + "node1" : "2", + "node2" : "6", + "busNode1" : "3", + "busNode2" : "6", + "type" : "ThreeWtEdge" + }, { + "svgId" : "9", + "equipmentId" : "3WT", + "node1" : "4", + "node2" : "6", + "busNode1" : "5", + "busNode2" : "6", + "type" : "ThreeWtEdge" + } ], + "textNodes" : [ { + "svgId" : "0-textnode", + "equipmentId" : "VL_11", + "vlNode" : "0", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "2-textnode", + "equipmentId" : "VL_132", + "vlNode" : "2", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "4-textnode", + "equipmentId" : "VL_33", + "vlNode" : "4", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + } ] +} diff --git a/network-area-diagram/src/test/resources/3wt_partial.svg b/network-area-diagram/src/test/resources/3wt_partial.svg index 25bfc2f88..be18bf2b6 100644 --- a/network-area-diagram/src/test/resources/3wt_partial.svg +++ b/network-area-diagram/src/test/resources/3wt_partial.svg @@ -44,31 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - VL_11 diff --git a/network-area-diagram/src/test/resources/IEEE_118_bus.svg b/network-area-diagram/src/test/resources/IEEE_118_bus.svg index 6980187ce..9ef2993ff 100644 --- a/network-area-diagram/src/test/resources/IEEE_118_bus.svg +++ b/network-area-diagram/src/test/resources/IEEE_118_bus.svg @@ -109,560 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_118_bus_partial.svg b/network-area-diagram/src/test/resources/IEEE_118_bus_partial.svg index 42b0b19c1..8df413a5d 100644 --- a/network-area-diagram/src/test/resources/IEEE_118_bus_partial.svg +++ b/network-area-diagram/src/test/resources/IEEE_118_bus_partial.svg @@ -109,152 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL42 diff --git a/network-area-diagram/src/test/resources/IEEE_118_bus_partial_non_connected.svg b/network-area-diagram/src/test/resources/IEEE_118_bus_partial_non_connected.svg index a91542800..9873dde28 100644 --- a/network-area-diagram/src/test/resources/IEEE_118_bus_partial_non_connected.svg +++ b/network-area-diagram/src/test/resources/IEEE_118_bus_partial_non_connected.svg @@ -109,113 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL113 diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus.svg b/network-area-diagram/src/test/resources/IEEE_14_bus.svg index 07983b9ff..082801d12 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus.svg @@ -44,76 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_disconnection.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_disconnection.svg index 09c99ce42..d4b95b9d5 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_disconnection.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_disconnection.svg @@ -44,73 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_fictitious.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_fictitious.svg index 7e32f6b00..1d759fa02 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_fictitious.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_fictitious.svg @@ -44,82 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_text_nodes.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_text_nodes.svg index c009b0c6d..a88e18713 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_text_nodes.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_text_nodes.svg @@ -44,82 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter1.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter1.svg index be9064e23..3fb8c481c 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter1.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter1.svg @@ -109,51 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2.svg index 67a04c0e4..5564ebfdc 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2.svg @@ -109,78 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter3.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter3.svg index a5a874843..8df69e1b3 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter3.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter3.svg @@ -109,59 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter4.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter4.svg index a6aec965a..4fad0b8b2 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter4.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter4.svg @@ -109,64 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5.svg index 8654d0217..c8d7806fb 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5.svg @@ -109,55 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/IEEE_14_id_prefixed.svg b/network-area-diagram/src/test/resources/IEEE_14_id_prefixed.svg index 564328334..f332ca83e 100644 --- a/network-area-diagram/src/test/resources/IEEE_14_id_prefixed.svg +++ b/network-area-diagram/src/test/resources/IEEE_14_id_prefixed.svg @@ -44,82 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_24_bus.svg b/network-area-diagram/src/test/resources/IEEE_24_bus.svg index aef63674d..3c4ccabeb 100644 --- a/network-area-diagram/src/test/resources/IEEE_24_bus.svg +++ b/network-area-diagram/src/test/resources/IEEE_24_bus.svg @@ -44,130 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_30_bus.svg b/network-area-diagram/src/test/resources/IEEE_30_bus.svg index a5a9745de..66c3a84d2 100644 --- a/network-area-diagram/src/test/resources/IEEE_30_bus.svg +++ b/network-area-diagram/src/test/resources/IEEE_30_bus.svg @@ -44,151 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/IEEE_57_bus.svg b/network-area-diagram/src/test/resources/IEEE_57_bus.svg index dc1ba7ce5..2fe2bbded 100644 --- a/network-area-diagram/src/test/resources/IEEE_57_bus.svg +++ b/network-area-diagram/src/test/resources/IEEE_57_bus.svg @@ -109,241 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/current_limits.svg b/network-area-diagram/src/test/resources/current_limits.svg index 54208fd82..a8c0a3711 100644 --- a/network-area-diagram/src/test/resources/current_limits.svg +++ b/network-area-diagram/src/test/resources/current_limits.svg @@ -44,30 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/dangling_line_connected.svg b/network-area-diagram/src/test/resources/dangling_line_connected.svg index 21da955ca..9863b351c 100644 --- a/network-area-diagram/src/test/resources/dangling_line_connected.svg +++ b/network-area-diagram/src/test/resources/dangling_line_connected.svg @@ -44,38 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/dangling_line_disconnected.svg b/network-area-diagram/src/test/resources/dangling_line_disconnected.svg index 25d49ce9a..866a2438f 100644 --- a/network-area-diagram/src/test/resources/dangling_line_disconnected.svg +++ b/network-area-diagram/src/test/resources/dangling_line_disconnected.svg @@ -44,38 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/detailed_text_node.svg b/network-area-diagram/src/test/resources/detailed_text_node.svg index d1c6aced3..a9f3d4992 100644 --- a/network-area-diagram/src/test/resources/detailed_text_node.svg +++ b/network-area-diagram/src/test/resources/detailed_text_node.svg @@ -109,30 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/detailed_text_node_no_legend.svg b/network-area-diagram/src/test/resources/detailed_text_node_no_legend.svg index d2b3382ac..c8344a3d9 100644 --- a/network-area-diagram/src/test/resources/detailed_text_node_no_legend.svg +++ b/network-area-diagram/src/test/resources/detailed_text_node_no_legend.svg @@ -109,30 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.0.svg b/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.0.svg index 0b14bc2de..2571ecaa5 100644 --- a/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.0.svg +++ b/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.0.svg @@ -44,81 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.2.svg b/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.2.svg index 58cfd09a1..44ece95a8 100644 --- a/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.2.svg +++ b/network-area-diagram/src/test/resources/diamond-spring-repulsion-factor-0.2.svg @@ -44,81 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/edge_info_current.svg b/network-area-diagram/src/test/resources/edge_info_current.svg index c47b7fd1a..b22b3080d 100644 --- a/network-area-diagram/src/test/resources/edge_info_current.svg +++ b/network-area-diagram/src/test/resources/edge_info_current.svg @@ -44,30 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - Voltage level 1 diff --git a/network-area-diagram/src/test/resources/edge_info_double_labels.svg b/network-area-diagram/src/test/resources/edge_info_double_labels.svg index e59022760..baebf541f 100644 --- a/network-area-diagram/src/test/resources/edge_info_double_labels.svg +++ b/network-area-diagram/src/test/resources/edge_info_double_labels.svg @@ -44,33 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/edge_info_missing_label.svg b/network-area-diagram/src/test/resources/edge_info_missing_label.svg index 0b445a11d..f907126f4 100644 --- a/network-area-diagram/src/test/resources/edge_info_missing_label.svg +++ b/network-area-diagram/src/test/resources/edge_info_missing_label.svg @@ -44,30 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/edge_info_perpendicular_label.svg b/network-area-diagram/src/test/resources/edge_info_perpendicular_label.svg index 219e7dd53..40abb80b3 100644 --- a/network-area-diagram/src/test/resources/edge_info_perpendicular_label.svg +++ b/network-area-diagram/src/test/resources/edge_info_perpendicular_label.svg @@ -44,30 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/edge_info_reactive_power.svg b/network-area-diagram/src/test/resources/edge_info_reactive_power.svg index 0f86263f4..fee1a255d 100644 --- a/network-area-diagram/src/test/resources/edge_info_reactive_power.svg +++ b/network-area-diagram/src/test/resources/edge_info_reactive_power.svg @@ -44,30 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - Voltage level 1 diff --git a/network-area-diagram/src/test/resources/edge_info_shift.svg b/network-area-diagram/src/test/resources/edge_info_shift.svg index eba324540..69f6e77a0 100644 --- a/network-area-diagram/src/test/resources/edge_info_shift.svg +++ b/network-area-diagram/src/test/resources/edge_info_shift.svg @@ -44,38 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/edge_with_id.svg b/network-area-diagram/src/test/resources/edge_with_id.svg index ea82a170b..ec5a45fa7 100644 --- a/network-area-diagram/src/test/resources/edge_with_id.svg +++ b/network-area-diagram/src/test/resources/edge_with_id.svg @@ -44,38 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/edge_without_id.svg b/network-area-diagram/src/test/resources/edge_without_id.svg index 21da955ca..9863b351c 100644 --- a/network-area-diagram/src/test/resources/edge_without_id.svg +++ b/network-area-diagram/src/test/resources/edge_without_id.svg @@ -44,38 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/hvdc-vl-depth-1.svg b/network-area-diagram/src/test/resources/hvdc-vl-depth-1.svg index 58c4836a9..73c1f6cbd 100644 --- a/network-area-diagram/src/test/resources/hvdc-vl-depth-1.svg +++ b/network-area-diagram/src/test/resources/hvdc-vl-depth-1.svg @@ -44,27 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - VL1 diff --git a/network-area-diagram/src/test/resources/hvdc.svg b/network-area-diagram/src/test/resources/hvdc.svg index 9c01f3f93..370ea708f 100644 --- a/network-area-diagram/src/test/resources/hvdc.svg +++ b/network-area-diagram/src/test/resources/hvdc.svg @@ -44,40 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - S1VL1 diff --git a/network-area-diagram/src/test/resources/hvdc_metadata.json b/network-area-diagram/src/test/resources/hvdc_metadata.json new file mode 100644 index 000000000..f49c239a1 --- /dev/null +++ b/network-area-diagram/src/test/resources/hvdc_metadata.json @@ -0,0 +1,197 @@ +{ + "layoutParameters" : { + "textNodesForceLayout" : false, + "springRepulsionFactorForceLayout" : 0.0, + "textNodeFixedShift" : { + "x" : 100.0, + "y" : -40.0 + }, + "maxSteps" : 1000, + "textNodeEdgeConnectionYShift" : 25.0 + }, + "svgParameters" : { + "diagramPadding" : { + "left" : 200.0, + "top" : 200.0, + "right" : 200.0, + "bottom" : 200.0 + }, + "insertNameDesc" : true, + "svgWidthAndHeightAdded" : true, + "cssLocation" : "INSERTED_IN_SVG", + "sizeConstraint" : "FIXED_SCALE", + "fixedWidth" : 800, + "fixedHeight" : -1, + "fixedScale" : 0.2, + "arrowShift" : 30.0, + "arrowLabelShift" : 19.0, + "converterStationWidth" : 70.0, + "voltageLevelCircleRadius" : 30.0, + "fictitiousVoltageLevelCircleRadius" : 15.0, + "transformerCircleRadius" : 20.0, + "nodeHollowWidth" : 15.0, + "edgesForkLength" : 80.0, + "edgesForkAperture" : 60.0, + "edgeStartShift" : 2.0, + "unknownBusNodeExtraRadius" : 10.0, + "loopDistance" : 120.0, + "loopEdgesAperture" : 60.0, + "loopControlDistance" : 40.0, + "edgeInfoAlongEdge" : true, + "edgeNameDisplayed" : false, + "interAnnulusSpace" : 5.0, + "svgPrefix" : "", + "idDisplayed" : false, + "substationDescriptionDisplayed" : false, + "arrowHeight" : 10.0, + "busLegend" : true, + "voltageLevelDetails" : false, + "languageTag" : "en", + "voltageValuePrecision" : 1, + "powerValuePrecision" : 0, + "angleValuePrecision" : 1, + "currentValuePrecision" : 0, + "edgeInfoDisplayed" : "ACTIVE_POWER", + "pstArrowHeadSize" : 8.0, + "undefinedValueSymbol" : "" + }, + "busNodes" : [ { + "svgId" : "1", + "equipmentId" : "S1VL1_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "0" + }, { + "svgId" : "3", + "equipmentId" : "S1VL2_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "2" + }, { + "svgId" : "5", + "equipmentId" : "S2VL1_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "4" + }, { + "svgId" : "7", + "equipmentId" : "S3VL1_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "6" + }, { + "svgId" : "9", + "equipmentId" : "S4VL1_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "8" + } ], + "nodes" : [ { + "svgId" : "0", + "equipmentId" : "S1VL1", + "x" : -220.4, + "y" : -515.14 + }, { + "svgId" : "2", + "equipmentId" : "S1VL2", + "x" : -152.34, + "y" : -133.8 + }, { + "svgId" : "4", + "equipmentId" : "S2VL1", + "x" : -162.93, + "y" : 231.51 + }, { + "svgId" : "6", + "equipmentId" : "S3VL1", + "x" : 171.13, + "y" : 91.69 + }, { + "svgId" : "8", + "equipmentId" : "S4VL1", + "x" : 497.34, + "y" : 302.31 + } ], + "edges" : [ { + "svgId" : "10", + "equipmentId" : "TWT", + "node1" : "0", + "node2" : "2", + "busNode1" : "1", + "busNode2" : "3", + "type" : "PstEdge" + }, { + "svgId" : "11", + "equipmentId" : "HVDC1", + "node1" : "2", + "node2" : "4", + "busNode1" : "3", + "busNode2" : "5", + "type" : "HvdcLineEdge" + }, { + "svgId" : "12", + "equipmentId" : "HVDC2", + "node1" : "2", + "node2" : "6", + "busNode1" : "3", + "busNode2" : "7", + "type" : "HvdcLineEdge" + }, { + "svgId" : "13", + "equipmentId" : "LINE_S2S3", + "node1" : "4", + "node2" : "6", + "busNode1" : "5", + "busNode2" : "7", + "type" : "LineEdge" + }, { + "svgId" : "14", + "equipmentId" : "LINE_S3S4", + "node1" : "6", + "node2" : "8", + "busNode1" : "7", + "busNode2" : "9", + "type" : "LineEdge" + } ], + "textNodes" : [ { + "svgId" : "0-textnode", + "equipmentId" : "S1VL1", + "vlNode" : "0", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "2-textnode", + "equipmentId" : "S1VL2", + "vlNode" : "2", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "4-textnode", + "equipmentId" : "S2VL1", + "vlNode" : "4", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "6-textnode", + "equipmentId" : "S3VL1", + "vlNode" : "6", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "8-textnode", + "equipmentId" : "S4VL1", + "vlNode" : "8", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + } ] +} diff --git a/network-area-diagram/src/test/resources/parallel_transformers.svg b/network-area-diagram/src/test/resources/parallel_transformers.svg index 9fc21c613..acc31c5d3 100644 --- a/network-area-diagram/src/test/resources/parallel_transformers.svg +++ b/network-area-diagram/src/test/resources/parallel_transformers.svg @@ -44,32 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/production_consumption_text_node.svg b/network-area-diagram/src/test/resources/production_consumption_text_node.svg index 0239a4632..75efeee80 100644 --- a/network-area-diagram/src/test/resources/production_consumption_text_node.svg +++ b/network-area-diagram/src/test/resources/production_consumption_text_node.svg @@ -109,38 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/production_consumption_text_node_nan.svg b/network-area-diagram/src/test/resources/production_consumption_text_node_nan.svg index 6e8be8b16..ecb1153b5 100644 --- a/network-area-diagram/src/test/resources/production_consumption_text_node_nan.svg +++ b/network-area-diagram/src/test/resources/production_consumption_text_node_nan.svg @@ -109,38 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/simple-eu-loop100.svg b/network-area-diagram/src/test/resources/simple-eu-loop100.svg index e40846a0e..fc0a48626 100644 --- a/network-area-diagram/src/test/resources/simple-eu-loop100.svg +++ b/network-area-diagram/src/test/resources/simple-eu-loop100.svg @@ -109,70 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BBE1AA1 diff --git a/network-area-diagram/src/test/resources/simple-eu-loop80.svg b/network-area-diagram/src/test/resources/simple-eu-loop80.svg index 15555dfd1..9a845f3bb 100644 --- a/network-area-diagram/src/test/resources/simple-eu-loop80.svg +++ b/network-area-diagram/src/test/resources/simple-eu-loop80.svg @@ -109,70 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BBE1AA1 diff --git a/network-area-diagram/src/test/resources/simple-eu.svg b/network-area-diagram/src/test/resources/simple-eu.svg index b30844e15..1afdbc167 100644 --- a/network-area-diagram/src/test/resources/simple-eu.svg +++ b/network-area-diagram/src/test/resources/simple-eu.svg @@ -109,70 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BBE1AA1 diff --git a/network-area-diagram/src/test/resources/tie_line.svg b/network-area-diagram/src/test/resources/tie_line.svg index c9c4775e5..eae95bd6f 100644 --- a/network-area-diagram/src/test/resources/tie_line.svg +++ b/network-area-diagram/src/test/resources/tie_line.svg @@ -44,36 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/tie_line_filtered.svg b/network-area-diagram/src/test/resources/tie_line_filtered.svg index 1cc33e65b..e6d3e8b63 100644 --- a/network-area-diagram/src/test/resources/tie_line_filtered.svg +++ b/network-area-diagram/src/test/resources/tie_line_filtered.svg @@ -44,35 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/vl_description_id.svg b/network-area-diagram/src/test/resources/vl_description_id.svg index 321237e0c..932a2a636 100644 --- a/network-area-diagram/src/test/resources/vl_description_id.svg +++ b/network-area-diagram/src/test/resources/vl_description_id.svg @@ -109,30 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/vl_description_substation.svg b/network-area-diagram/src/test/resources/vl_description_substation.svg index 3368bd8be..be95e634e 100644 --- a/network-area-diagram/src/test/resources/vl_description_substation.svg +++ b/network-area-diagram/src/test/resources/vl_description_substation.svg @@ -109,30 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/vl_description_substation_id.svg b/network-area-diagram/src/test/resources/vl_description_substation_id.svg index cb547f88e..60a74b4f9 100644 --- a/network-area-diagram/src/test/resources/vl_description_substation_id.svg +++ b/network-area-diagram/src/test/resources/vl_description_substation_id.svg @@ -109,30 +109,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/network-area-diagram/src/test/resources/voltage_limits.svg b/network-area-diagram/src/test/resources/voltage_limits.svg index 480ce01cb..80204ff51 100644 --- a/network-area-diagram/src/test/resources/voltage_limits.svg +++ b/network-area-diagram/src/test/resources/voltage_limits.svg @@ -44,32 +44,6 @@ path.nad-arrow-in:not(.nad-state-in .nad-arrow-in) {visibility: hidden} 40% {stroke: #00BCD4; stroke-width: 15} } ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - From 855dfd13ba2b109aed19a7759105278cc78645c4 Mon Sep 17 00:00:00 2001 From: "massimo.ferraro" Date: Thu, 26 Sep 2024 12:24:55 +0200 Subject: [PATCH 2/7] Fix code duplication and increase test coverage Signed-off-by: massimo.ferraro --- .../diagram/metadata/AbstractMetadata.java | 42 + .../com/powsybl/nad/NetworkAreaDiagram.java | 10 +- .../nad/svg/metadata/DiagramMetadata.java | 25 +- .../java/com/powsybl/nad/AbstractTest.java | 2 +- .../powsybl/nad/NetworkAreaDiagramTest.java | 87 ++ .../powsybl/nad/svg/DiagramMetadataTest.java | 28 +- .../IEEE_14_bus_voltage_filter2_metadata.json | 456 +++++++++ .../IEEE_14_bus_voltage_filter5_metadata.json | 297 ++++++ .../IEEE_14_bus_voltage_nofilter.svg | 890 ++++++++++++++++++ ...IEEE_14_bus_voltage_nofilter_metadata.json | 488 ++++++++++ .../com/powsybl/sld/svg/GraphMetadata.java | 24 +- 11 files changed, 2288 insertions(+), 61 deletions(-) create mode 100644 diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java create mode 100644 network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2_metadata.json create mode 100644 network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5_metadata.json create mode 100644 network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter.svg create mode 100644 network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter_metadata.json diff --git a/diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java b/diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java new file mode 100644 index 000000000..13647e9f9 --- /dev/null +++ b/diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com/) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.diagram.metadata; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Objects; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.powsybl.commons.json.JsonUtil; + +public abstract class AbstractMetadata { + + public void writeJson(Path file) { + Objects.requireNonNull(file); + try (Writer writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { + writeJson(writer); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public void writeJson(Writer writer) { + Objects.requireNonNull(writer); + ObjectMapper objectMapper = JsonUtil.createObjectMapper(); + try { + objectMapper.writerWithDefaultPrettyPrinter() + .writeValue(writer, this); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } +} diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index 4dfdd163c..419ca1a31 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -26,6 +26,8 @@ import java.util.Objects; import java.util.function.Predicate; +import org.apache.commons.io.output.NullWriter; + /** * @author Florian Dupuy {@literal } */ @@ -62,7 +64,7 @@ public static void draw(Network network, Path svgFile, List voltageLevel draw(network, svgFile, new NadParameters(), VoltageLevelFilter.createVoltageLevelsDepthFilter(network, voltageLevelIds, depth)); } - public void draw(Network network, Writer writer, Writer metadataWriter, Predicate voltageLevelFilter) { + public static void draw(Network network, Writer writer, Writer metadataWriter, Predicate voltageLevelFilter) { draw(network, writer, metadataWriter, new NadParameters(), voltageLevelFilter); } @@ -110,10 +112,10 @@ private static void genericDraw(Network network, Object svgObject, Object metada } } - public String drawToString(Network network, SvgParameters svgParameters) { - try (StringWriter writer = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { + public static String drawToString(Network network, SvgParameters svgParameters) { + try (StringWriter writer = new StringWriter()) { NadParameters nadParameters = new NadParameters().setSvgParameters(svgParameters); - draw(network, writer, metadataWriter, nadParameters, VoltageLevelFilter.NO_FILTER); + draw(network, writer, NullWriter.INSTANCE, nadParameters, VoltageLevelFilter.NO_FILTER); return writer.toString(); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java index 44e5eed81..2f68946c3 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java @@ -11,8 +11,6 @@ import java.io.InputStream; import java.io.Reader; import java.io.UncheckedIOException; -import java.io.Writer; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -23,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.diagram.metadata.AbstractMetadata; import com.powsybl.nad.layout.LayoutParameters; import com.powsybl.nad.model.Graph; import com.powsybl.nad.svg.SvgParameters; @@ -30,7 +29,7 @@ /** * @author Thomas Adam {@literal } */ -public class DiagramMetadata { +public class DiagramMetadata extends AbstractMetadata { private final LayoutParameters layoutParameters; private final SvgParameters svgParameters; @@ -171,24 +170,4 @@ public static DiagramMetadata parseJson(Reader reader) { throw new UncheckedIOException(e); } } - - public void writeJson(Path file) { - Objects.requireNonNull(file); - try (Writer writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { - writeJson(writer); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public void writeJson(Writer writer) { - Objects.requireNonNull(writer); - ObjectMapper objectMapper = JsonUtil.createObjectMapper(); - try { - objectMapper.writerWithDefaultPrettyPrinter() - .writeValue(writer, this); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } } diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java index 4a6f3025d..8022580b1 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java @@ -96,7 +96,7 @@ protected String toString(String resourceName) { } } - private static String normalizeLineSeparator(String str) { + protected static String normalizeLineSeparator(String str) { return str.replace("\r\n", "\n") .replace("\r", "\n"); } diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java index 4d74ebb70..e8e53e29b 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/NetworkAreaDiagramTest.java @@ -28,6 +28,10 @@ import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; +import java.io.Writer; +import java.io.IOException; +import java.io.StringWriter; +import java.io.UncheckedIOException; import java.nio.file.FileSystem; import java.nio.file.Path; import java.util.List; @@ -171,4 +175,87 @@ void testVoltageFilteredDiagramUnexistingVoltageLevel() { PowsyblException e = assertThrows(PowsyblException.class, () -> VoltageLevelFilter.createNominalVoltageUpperBoundFilter(network, voltageLevelList, 90, 2)); assertTrue(e.getMessage().contains("Unknown voltage level id 'VL456'")); } + + @Test + void testDraw() { + Network network = IeeeCdfNetworkFactory.create14(); + // test writers + try (Writer svgWriter = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { + NetworkAreaDiagram.draw(network, svgWriter, metadataWriter); + assertEquals(toString("/IEEE_14_bus_voltage_nofilter.svg"), normalizeLineSeparator(svgWriter.toString())); + assertEquals(toString("/IEEE_14_bus_voltage_nofilter_metadata.json").trim(), normalizeLineSeparator(metadataWriter.toString())); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + // test files + Path svgFile = fileSystem.getPath("nad-ieee-14-bus.svg"); + NetworkAreaDiagram.draw(network, svgFile); + assertEquals(toString("/IEEE_14_bus_voltage_nofilter.svg"), getContentFile(svgFile)); + Path metadataFile = fileSystem.getPath("nad-ieee-14-bus_metadata.json"); + assertEquals(toString("/IEEE_14_bus_voltage_nofilter_metadata.json"), getContentFile(metadataFile)); + } + + @Test + void testDrawToString() { + Network network = IeeeCdfNetworkFactory.create14(); + String svg = NetworkAreaDiagram.drawToString(network, new SvgParameters()); + assertEquals(toString("/IEEE_14_bus_voltage_nofilter.svg"), svg); + } + + @Test + void testDrawWithFilter() { + Network network = IeeeCdfNetworkFactory.create14(); + try (Writer svgWriter = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { + NetworkAreaDiagram.draw(network, svgWriter, metadataWriter, VoltageLevelFilter.createNominalVoltageLowerBoundFilter(network, 20)); + assertEquals(toString("/IEEE_14_bus_voltage_filter5.svg"), normalizeLineSeparator(svgWriter.toString())); + assertEquals(toString("/IEEE_14_bus_voltage_filter5_metadata.json").trim(), normalizeLineSeparator(metadataWriter.toString())); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + @Test + void testDrawWithVoltageLevel() { + Network network = IeeeCdfNetworkFactory.create14(); + // test writers + try (Writer svgWriter = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { + NetworkAreaDiagram.draw(network, svgWriter, metadataWriter, "VL4", 2); + assertEquals(toString("/IEEE_14_bus_voltage_filter2.svg"), normalizeLineSeparator(svgWriter.toString())); + assertEquals(toString("/IEEE_14_bus_voltage_filter2_metadata.json").trim(), normalizeLineSeparator(metadataWriter.toString())); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + // test files + Path svgFile = fileSystem.getPath("nad-ieee-14-bus.svg"); + NetworkAreaDiagram.draw(network, svgFile, "VL4", 2); + assertEquals(toString("/IEEE_14_bus_voltage_filter2.svg"), getContentFile(svgFile)); + Path metadataFile = fileSystem.getPath("nad-ieee-14-bus_metadata.json"); + assertEquals(toString("/IEEE_14_bus_voltage_filter2_metadata.json"), getContentFile(metadataFile)); + + Path svgFile2 = fileSystem.getPath("nad-ieee-14-bus2.svg"); + NetworkAreaDiagram.draw(network, svgFile2, List.of("VL4"), 2); + assertEquals(toString("/IEEE_14_bus_voltage_filter2.svg"), getContentFile(svgFile2)); + Path metadataFile2 = fileSystem.getPath("nad-ieee-14-bus2_metadata.json"); + assertEquals(toString("/IEEE_14_bus_voltage_filter2_metadata.json"), getContentFile(metadataFile2)); + + } + + @Test + void testDrawWithVoltageLevels() { + Network network = IeeeCdfNetworkFactory.create14(); + // test writers + try (Writer svgWriter = new StringWriter(); StringWriter metadataWriter = new StringWriter()) { + NetworkAreaDiagram.draw(network, svgWriter, metadataWriter, List.of("VL1", "VL2", "VL3", "VL4", "VL5", "VL8")); + assertEquals(toString("/IEEE_14_bus_voltage_filter5.svg"), normalizeLineSeparator(svgWriter.toString())); + assertEquals(toString("/IEEE_14_bus_voltage_filter5_metadata.json").trim(), normalizeLineSeparator(metadataWriter.toString())); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + // test files + Path svgFile = fileSystem.getPath("nad-ieee-14-bus.svg"); + NetworkAreaDiagram.draw(network, svgFile, List.of("VL1", "VL2", "VL3", "VL4", "VL5", "VL8")); + assertEquals(toString("/IEEE_14_bus_voltage_filter5.svg"), getContentFile(svgFile)); + Path metadataFile = fileSystem.getPath("nad-ieee-14-bus_metadata.json"); + assertEquals(toString("/IEEE_14_bus_voltage_filter5_metadata.json"), getContentFile(metadataFile)); + } } diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java index fd8dc6176..198daa635 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/svg/DiagramMetadataTest.java @@ -69,17 +69,17 @@ protected LabelProvider getLabelProvider(Network network) { @Test void test() { // Referenced json file - String reference = "/hvdc_metadata.json"; - InputStream in = Objects.requireNonNull(getClass().getResourceAsStream(reference)); + String referenceMetadata = "/hvdc_metadata.json"; + InputStream in = Objects.requireNonNull(getClass().getResourceAsStream(referenceMetadata)); // Create Metadata from json file DiagramMetadata metadata = DiagramMetadata.parseJson(in); // Write Metadata as temporary json file - Path outPath = tmpDir.resolve("metadata.json"); - writeMetadata(metadata, outPath); + Path outMetadataPath = tmpDir.resolve("metadata.json"); + writeMetadata(metadata, outMetadataPath); // Read generated json file - String actual = getContentFile(outPath); + String actual = getContentFile(outMetadataPath); // Read reference json file - String expected = toString(reference); + String expected = toString(referenceMetadata); // Checking assertEquals(expected, actual); } @@ -87,19 +87,25 @@ void test() { @Test void test3wt() { // Referenced json file - String reference = "/3wt_metadata.json"; + String referenceMetadata = "/3wt_metadata.json"; // Write Metadata as temporary json file Network network = ThreeWindingsTransformerNetworkFactory.create(); Graph graph = new NetworkGraphBuilder(network, VoltageLevelFilter.NO_FILTER).buildGraph(); new BasicForceLayout().run(graph, getLayoutParameters()); - Path outPath = tmpDir.resolve("metadata.json"); - new DiagramMetadata(getLayoutParameters(), getSvgParameters()).addMetadata(graph).writeJson(outPath); + Path outMetadataPath = tmpDir.resolve("metadata.json"); + new DiagramMetadata(getLayoutParameters(), getSvgParameters()).addMetadata(graph).writeJson(outMetadataPath); // Read generated json file - String actual = getContentFile(outPath); + String actual = getContentFile(outMetadataPath); // Read reference json file - String expected = toString(reference); + String expected = toString(referenceMetadata); // Checking assertEquals(expected, actual); + // Read metadata from file + DiagramMetadata diagramMetadata = DiagramMetadata.parseJson(outMetadataPath); + assertEquals(3, diagramMetadata.getBusNodesMetadata().size()); + assertEquals(4, diagramMetadata.getNodesMetadata().size()); + assertEquals(3, diagramMetadata.getEdgesMetadata().size()); + assertEquals(3, diagramMetadata.getTextNodesMetadata().size()); } private void writeMetadata(DiagramMetadata metadata, Path outPath) { diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2_metadata.json b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2_metadata.json new file mode 100644 index 000000000..deee2ad53 --- /dev/null +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2_metadata.json @@ -0,0 +1,456 @@ +{ + "layoutParameters" : { + "textNodesForceLayout" : false, + "springRepulsionFactorForceLayout" : 0.0, + "textNodeFixedShift" : { + "x" : 100.0, + "y" : -40.0 + }, + "maxSteps" : 1000, + "textNodeEdgeConnectionYShift" : 25.0 + }, + "svgParameters" : { + "diagramPadding" : { + "left" : 200.0, + "top" : 200.0, + "right" : 200.0, + "bottom" : 200.0 + }, + "insertNameDesc" : false, + "svgWidthAndHeightAdded" : false, + "cssLocation" : "INSERTED_IN_SVG", + "sizeConstraint" : "FIXED_SCALE", + "fixedWidth" : -1, + "fixedHeight" : -1, + "fixedScale" : 0.2, + "arrowShift" : 30.0, + "arrowLabelShift" : 19.0, + "converterStationWidth" : 70.0, + "voltageLevelCircleRadius" : 30.0, + "fictitiousVoltageLevelCircleRadius" : 15.0, + "transformerCircleRadius" : 20.0, + "nodeHollowWidth" : 15.0, + "edgesForkLength" : 80.0, + "edgesForkAperture" : 60.0, + "edgeStartShift" : 0.0, + "unknownBusNodeExtraRadius" : 10.0, + "loopDistance" : 120.0, + "loopEdgesAperture" : 60.0, + "loopControlDistance" : 40.0, + "edgeInfoAlongEdge" : true, + "edgeNameDisplayed" : false, + "interAnnulusSpace" : 5.0, + "svgPrefix" : "", + "idDisplayed" : false, + "substationDescriptionDisplayed" : false, + "arrowHeight" : 10.0, + "busLegend" : true, + "voltageLevelDetails" : false, + "languageTag" : "en", + "voltageValuePrecision" : 1, + "powerValuePrecision" : 0, + "angleValuePrecision" : 1, + "currentValuePrecision" : 0, + "edgeInfoDisplayed" : "ACTIVE_POWER", + "pstArrowHeadSize" : 8.0, + "undefinedValueSymbol" : "" + }, + "busNodes" : [ { + "svgId" : "1", + "equipmentId" : "VL1_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "0" + }, { + "svgId" : "3", + "equipmentId" : "VL10_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "2" + }, { + "svgId" : "5", + "equipmentId" : "VL14_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "4" + }, { + "svgId" : "7", + "equipmentId" : "VL2_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "6" + }, { + "svgId" : "9", + "equipmentId" : "VL3_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "8" + }, { + "svgId" : "11", + "equipmentId" : "VL4_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "10" + }, { + "svgId" : "13", + "equipmentId" : "VL5_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "12" + }, { + "svgId" : "15", + "equipmentId" : "VL6_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "14" + }, { + "svgId" : "17", + "equipmentId" : "VL7_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "16" + }, { + "svgId" : "19", + "equipmentId" : "VL8_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "18" + }, { + "svgId" : "21", + "equipmentId" : "VL9_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "20" + }, { + "svgId" : "23", + "equipmentId" : "VL11_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "22" + }, { + "svgId" : "25", + "equipmentId" : "VL12_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "24" + }, { + "svgId" : "27", + "equipmentId" : "VL13_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "26" + } ], + "nodes" : [ { + "svgId" : "0", + "equipmentId" : "VL1", + "x" : 948.69, + "y" : -322.21 + }, { + "svgId" : "2", + "equipmentId" : "VL10", + "x" : -358.9, + "y" : 525.37 + }, { + "svgId" : "4", + "equipmentId" : "VL14", + "x" : -359.39, + "y" : -476.71 + }, { + "svgId" : "6", + "equipmentId" : "VL2", + "x" : 590.54, + "y" : -374.08 + }, { + "svgId" : "8", + "equipmentId" : "VL3", + "x" : 314.39, + "y" : -324.77 + }, { + "svgId" : "10", + "equipmentId" : "VL4", + "x" : 56.2, + "y" : -94.68 + }, { + "svgId" : "12", + "equipmentId" : "VL5", + "x" : 608.23, + "y" : -31.45 + }, { + "svgId" : "14", + "equipmentId" : "VL6", + "x" : 351.34, + "y" : 284.99 + }, { + "svgId" : "16", + "equipmentId" : "VL7", + "x" : -630.2, + "y" : -157.55 + }, { + "svgId" : "18", + "equipmentId" : "VL8", + "x" : -1033.21, + "y" : -350.22 + }, { + "svgId" : "20", + "equipmentId" : "VL9", + "x" : -365.55, + "y" : 38.7 + }, { + "svgId" : "22", + "equipmentId" : "VL11", + "x" : 32.17, + "y" : 653.29 + }, { + "svgId" : "24", + "equipmentId" : "VL12", + "x" : 692.44, + "y" : 630.83 + }, { + "svgId" : "26", + "equipmentId" : "VL13", + "x" : -5.18, + "y" : -428.32 + } ], + "edges" : [ { + "svgId" : "28", + "equipmentId" : "L1-2-1", + "node1" : "0", + "node2" : "6", + "busNode1" : "1", + "busNode2" : "7", + "type" : "LineEdge" + }, { + "svgId" : "29", + "equipmentId" : "L1-5-1", + "node1" : "0", + "node2" : "12", + "busNode1" : "1", + "busNode2" : "13", + "type" : "LineEdge" + }, { + "svgId" : "30", + "equipmentId" : "L9-10-1", + "node1" : "20", + "node2" : "2", + "busNode1" : "21", + "busNode2" : "3", + "type" : "LineEdge" + }, { + "svgId" : "31", + "equipmentId" : "L10-11-1", + "node1" : "2", + "node2" : "22", + "busNode1" : "3", + "busNode2" : "23", + "type" : "LineEdge" + }, { + "svgId" : "32", + "equipmentId" : "L9-14-1", + "node1" : "20", + "node2" : "4", + "busNode1" : "21", + "busNode2" : "5", + "type" : "LineEdge" + }, { + "svgId" : "33", + "equipmentId" : "L13-14-1", + "node1" : "26", + "node2" : "4", + "busNode1" : "27", + "busNode2" : "5", + "type" : "LineEdge" + }, { + "svgId" : "34", + "equipmentId" : "L2-3-1", + "node1" : "6", + "node2" : "8", + "busNode1" : "7", + "busNode2" : "9", + "type" : "LineEdge" + }, { + "svgId" : "35", + "equipmentId" : "L2-4-1", + "node1" : "6", + "node2" : "10", + "busNode1" : "7", + "busNode2" : "11", + "type" : "LineEdge" + }, { + "svgId" : "36", + "equipmentId" : "L2-5-1", + "node1" : "6", + "node2" : "12", + "busNode1" : "7", + "busNode2" : "13", + "type" : "LineEdge" + }, { + "svgId" : "37", + "equipmentId" : "L3-4-1", + "node1" : "8", + "node2" : "10", + "busNode1" : "9", + "busNode2" : "11", + "type" : "LineEdge" + }, { + "svgId" : "38", + "equipmentId" : "L4-5-1", + "node1" : "10", + "node2" : "12", + "busNode1" : "11", + "busNode2" : "13", + "type" : "LineEdge" + }, { + "svgId" : "39", + "equipmentId" : "T4-7-1", + "node1" : "10", + "node2" : "16", + "busNode1" : "11", + "busNode2" : "17", + "type" : "TwoWtEdge" + }, { + "svgId" : "40", + "equipmentId" : "T4-9-1", + "node1" : "10", + "node2" : "20", + "busNode1" : "11", + "busNode2" : "21", + "type" : "TwoWtEdge" + }, { + "svgId" : "41", + "equipmentId" : "T5-6-1", + "node1" : "12", + "node2" : "14", + "busNode1" : "13", + "busNode2" : "15", + "type" : "TwoWtEdge" + }, { + "svgId" : "42", + "equipmentId" : "L6-11-1", + "node1" : "14", + "node2" : "22", + "busNode1" : "15", + "busNode2" : "23", + "type" : "LineEdge" + }, { + "svgId" : "43", + "equipmentId" : "L6-12-1", + "node1" : "14", + "node2" : "24", + "busNode1" : "15", + "busNode2" : "25", + "type" : "LineEdge" + }, { + "svgId" : "44", + "equipmentId" : "L6-13-1", + "node1" : "14", + "node2" : "26", + "busNode1" : "15", + "busNode2" : "27", + "type" : "LineEdge" + }, { + "svgId" : "45", + "equipmentId" : "L7-8-1", + "node1" : "16", + "node2" : "18", + "busNode1" : "17", + "busNode2" : "19", + "type" : "LineEdge" + }, { + "svgId" : "46", + "equipmentId" : "L7-9-1", + "node1" : "16", + "node2" : "20", + "busNode1" : "17", + "busNode2" : "21", + "type" : "LineEdge" + } ], + "textNodes" : [ { + "svgId" : "0-textnode", + "equipmentId" : "VL1", + "vlNode" : "0", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "2-textnode", + "equipmentId" : "VL10", + "vlNode" : "2", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "4-textnode", + "equipmentId" : "VL14", + "vlNode" : "4", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "6-textnode", + "equipmentId" : "VL2", + "vlNode" : "6", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "8-textnode", + "equipmentId" : "VL3", + "vlNode" : "8", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "10-textnode", + "equipmentId" : "VL4", + "vlNode" : "10", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "12-textnode", + "equipmentId" : "VL5", + "vlNode" : "12", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "14-textnode", + "equipmentId" : "VL6", + "vlNode" : "14", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "16-textnode", + "equipmentId" : "VL7", + "vlNode" : "16", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "18-textnode", + "equipmentId" : "VL8", + "vlNode" : "18", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "20-textnode", + "equipmentId" : "VL9", + "vlNode" : "20", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + } ] +} diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5_metadata.json b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5_metadata.json new file mode 100644 index 000000000..490524560 --- /dev/null +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5_metadata.json @@ -0,0 +1,297 @@ +{ + "layoutParameters" : { + "textNodesForceLayout" : false, + "springRepulsionFactorForceLayout" : 0.0, + "textNodeFixedShift" : { + "x" : 100.0, + "y" : -40.0 + }, + "maxSteps" : 1000, + "textNodeEdgeConnectionYShift" : 25.0 + }, + "svgParameters" : { + "diagramPadding" : { + "left" : 200.0, + "top" : 200.0, + "right" : 200.0, + "bottom" : 200.0 + }, + "insertNameDesc" : false, + "svgWidthAndHeightAdded" : false, + "cssLocation" : "INSERTED_IN_SVG", + "sizeConstraint" : "FIXED_SCALE", + "fixedWidth" : -1, + "fixedHeight" : -1, + "fixedScale" : 0.2, + "arrowShift" : 30.0, + "arrowLabelShift" : 19.0, + "converterStationWidth" : 70.0, + "voltageLevelCircleRadius" : 30.0, + "fictitiousVoltageLevelCircleRadius" : 15.0, + "transformerCircleRadius" : 20.0, + "nodeHollowWidth" : 15.0, + "edgesForkLength" : 80.0, + "edgesForkAperture" : 60.0, + "edgeStartShift" : 0.0, + "unknownBusNodeExtraRadius" : 10.0, + "loopDistance" : 120.0, + "loopEdgesAperture" : 60.0, + "loopControlDistance" : 40.0, + "edgeInfoAlongEdge" : true, + "edgeNameDisplayed" : false, + "interAnnulusSpace" : 5.0, + "svgPrefix" : "", + "idDisplayed" : false, + "substationDescriptionDisplayed" : false, + "arrowHeight" : 10.0, + "busLegend" : true, + "voltageLevelDetails" : false, + "languageTag" : "en", + "voltageValuePrecision" : 1, + "powerValuePrecision" : 0, + "angleValuePrecision" : 1, + "currentValuePrecision" : 0, + "edgeInfoDisplayed" : "ACTIVE_POWER", + "pstArrowHeadSize" : 8.0, + "undefinedValueSymbol" : "" + }, + "busNodes" : [ { + "svgId" : "1", + "equipmentId" : "VL1_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "0" + }, { + "svgId" : "3", + "equipmentId" : "VL2_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "2" + }, { + "svgId" : "5", + "equipmentId" : "VL3_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "4" + }, { + "svgId" : "7", + "equipmentId" : "VL4_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "6" + }, { + "svgId" : "9", + "equipmentId" : "VL5_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "8" + }, { + "svgId" : "11", + "equipmentId" : "VL8_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "10" + }, { + "svgId" : "13", + "equipmentId" : "VL6_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "12" + }, { + "svgId" : "15", + "equipmentId" : "VL7_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "14" + }, { + "svgId" : "17", + "equipmentId" : "VL9_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "16" + } ], + "nodes" : [ { + "svgId" : "0", + "equipmentId" : "VL1", + "x" : -249.02, + "y" : 337.72 + }, { + "svgId" : "2", + "equipmentId" : "VL2", + "x" : -241.09, + "y" : -38.49 + }, { + "svgId" : "4", + "equipmentId" : "VL3", + "x" : -379.91, + "y" : -377.15 + }, { + "svgId" : "6", + "equipmentId" : "VL4", + "x" : 43.65, + "y" : -307.91 + }, { + "svgId" : "8", + "equipmentId" : "VL5", + "x" : 103.37, + "y" : 126.77 + }, { + "svgId" : "10", + "equipmentId" : "VL8", + "x" : 409.59, + "y" : 481.85 + }, { + "svgId" : "12", + "equipmentId" : "VL6", + "x" : 683.08, + "y" : 250.21 + }, { + "svgId" : "14", + "equipmentId" : "VL7", + "x" : 443.55, + "y" : -67.88 + }, { + "svgId" : "16", + "equipmentId" : "VL9", + "x" : 95.54, + "y" : -762.33 + } ], + "edges" : [ { + "svgId" : "18", + "equipmentId" : "L1-2-1", + "node1" : "0", + "node2" : "2", + "busNode1" : "1", + "busNode2" : "3", + "type" : "LineEdge" + }, { + "svgId" : "19", + "equipmentId" : "L1-5-1", + "node1" : "0", + "node2" : "8", + "busNode1" : "1", + "busNode2" : "9", + "type" : "LineEdge" + }, { + "svgId" : "20", + "equipmentId" : "L2-3-1", + "node1" : "2", + "node2" : "4", + "busNode1" : "3", + "busNode2" : "5", + "type" : "LineEdge" + }, { + "svgId" : "21", + "equipmentId" : "L2-4-1", + "node1" : "2", + "node2" : "6", + "busNode1" : "3", + "busNode2" : "7", + "type" : "LineEdge" + }, { + "svgId" : "22", + "equipmentId" : "L2-5-1", + "node1" : "2", + "node2" : "8", + "busNode1" : "3", + "busNode2" : "9", + "type" : "LineEdge" + }, { + "svgId" : "23", + "equipmentId" : "L3-4-1", + "node1" : "4", + "node2" : "6", + "busNode1" : "5", + "busNode2" : "7", + "type" : "LineEdge" + }, { + "svgId" : "24", + "equipmentId" : "L4-5-1", + "node1" : "6", + "node2" : "8", + "busNode1" : "7", + "busNode2" : "9", + "type" : "LineEdge" + }, { + "svgId" : "25", + "equipmentId" : "T4-7-1", + "node1" : "6", + "node2" : "14", + "busNode1" : "7", + "busNode2" : "15", + "type" : "TwoWtEdge" + }, { + "svgId" : "26", + "equipmentId" : "T4-9-1", + "node1" : "6", + "node2" : "16", + "busNode1" : "7", + "busNode2" : "17", + "type" : "TwoWtEdge" + }, { + "svgId" : "27", + "equipmentId" : "T5-6-1", + "node1" : "8", + "node2" : "12", + "busNode1" : "9", + "busNode2" : "13", + "type" : "TwoWtEdge" + }, { + "svgId" : "28", + "equipmentId" : "L7-8-1", + "node1" : "14", + "node2" : "10", + "busNode1" : "15", + "busNode2" : "11", + "type" : "LineEdge" + } ], + "textNodes" : [ { + "svgId" : "0-textnode", + "equipmentId" : "VL1", + "vlNode" : "0", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "2-textnode", + "equipmentId" : "VL2", + "vlNode" : "2", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "4-textnode", + "equipmentId" : "VL3", + "vlNode" : "4", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "6-textnode", + "equipmentId" : "VL4", + "vlNode" : "6", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "8-textnode", + "equipmentId" : "VL5", + "vlNode" : "8", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "10-textnode", + "equipmentId" : "VL8", + "vlNode" : "10", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + } ] +} diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter.svg b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter.svg new file mode 100644 index 000000000..aec83ef0b --- /dev/null +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter.svg @@ -0,0 +1,890 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
VL1
+ + + + + +
+
+
143.1 kV / 0.0°
+
+
+ +
+
VL10
+ + + + + +
+
+
12.6 kV / -15.1°
+
+
+ +
+
VL11
+ + + + + +
+
+
12.7 kV / -14.8°
+
+
+ +
+
VL12
+ + + + + +
+
+
12.7 kV / -15.1°
+
+
+ +
+
VL13
+ + + + + +
+
+
12.6 kV / -15.2°
+
+
+ +
+
VL14
+ + + + + +
+
+
12.4 kV / -16.0°
+
+
+ +
+
VL2
+ + + + + +
+
+
141.1 kV / -5.0°
+
+
+ +
+
VL3
+ + + + + +
+
+
136.3 kV / -12.7°
+
+
+ +
+
VL4
+ + + + + +
+
+
137.6 kV / -10.3°
+
+
+ +
+
VL5
+ + + + + +
+
+
137.7 kV / -8.8°
+
+
+ +
+
VL6
+ + + + + +
+
+
12.8 kV / -14.2°
+
+
+ +
+
VL7
+ + + + + +
+
+
14.9 kV / -13.4°
+
+
+ +
+
VL8
+ + + + + +
+
+
21.8 kV / -13.4°
+
+
+ +
+
VL9
+ + + + + +
+
+
12.7 kV / -14.9°
+
+
+
+
diff --git a/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter_metadata.json b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter_metadata.json new file mode 100644 index 000000000..56386ae3f --- /dev/null +++ b/network-area-diagram/src/test/resources/IEEE_14_bus_voltage_nofilter_metadata.json @@ -0,0 +1,488 @@ +{ + "layoutParameters" : { + "textNodesForceLayout" : false, + "springRepulsionFactorForceLayout" : 0.0, + "textNodeFixedShift" : { + "x" : 100.0, + "y" : -40.0 + }, + "maxSteps" : 1000, + "textNodeEdgeConnectionYShift" : 25.0 + }, + "svgParameters" : { + "diagramPadding" : { + "left" : 200.0, + "top" : 200.0, + "right" : 200.0, + "bottom" : 200.0 + }, + "insertNameDesc" : false, + "svgWidthAndHeightAdded" : false, + "cssLocation" : "INSERTED_IN_SVG", + "sizeConstraint" : "FIXED_SCALE", + "fixedWidth" : -1, + "fixedHeight" : -1, + "fixedScale" : 0.2, + "arrowShift" : 30.0, + "arrowLabelShift" : 19.0, + "converterStationWidth" : 70.0, + "voltageLevelCircleRadius" : 30.0, + "fictitiousVoltageLevelCircleRadius" : 15.0, + "transformerCircleRadius" : 20.0, + "nodeHollowWidth" : 15.0, + "edgesForkLength" : 80.0, + "edgesForkAperture" : 60.0, + "edgeStartShift" : 0.0, + "unknownBusNodeExtraRadius" : 10.0, + "loopDistance" : 120.0, + "loopEdgesAperture" : 60.0, + "loopControlDistance" : 40.0, + "edgeInfoAlongEdge" : true, + "edgeNameDisplayed" : false, + "interAnnulusSpace" : 5.0, + "svgPrefix" : "", + "idDisplayed" : false, + "substationDescriptionDisplayed" : false, + "arrowHeight" : 10.0, + "busLegend" : true, + "voltageLevelDetails" : false, + "languageTag" : "en", + "voltageValuePrecision" : 1, + "powerValuePrecision" : 0, + "angleValuePrecision" : 1, + "currentValuePrecision" : 0, + "edgeInfoDisplayed" : "ACTIVE_POWER", + "pstArrowHeadSize" : 8.0, + "undefinedValueSymbol" : "" + }, + "busNodes" : [ { + "svgId" : "1", + "equipmentId" : "VL1_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "0" + }, { + "svgId" : "3", + "equipmentId" : "VL10_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "2" + }, { + "svgId" : "5", + "equipmentId" : "VL11_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "4" + }, { + "svgId" : "7", + "equipmentId" : "VL12_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "6" + }, { + "svgId" : "9", + "equipmentId" : "VL13_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "8" + }, { + "svgId" : "11", + "equipmentId" : "VL14_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "10" + }, { + "svgId" : "13", + "equipmentId" : "VL2_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "12" + }, { + "svgId" : "15", + "equipmentId" : "VL3_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "14" + }, { + "svgId" : "17", + "equipmentId" : "VL4_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "16" + }, { + "svgId" : "19", + "equipmentId" : "VL5_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "18" + }, { + "svgId" : "21", + "equipmentId" : "VL6_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "20" + }, { + "svgId" : "23", + "equipmentId" : "VL7_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "22" + }, { + "svgId" : "25", + "equipmentId" : "VL8_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "24" + }, { + "svgId" : "27", + "equipmentId" : "VL9_0", + "nbNeighbours" : 0, + "index" : 0, + "vlNode" : "26" + } ], + "nodes" : [ { + "svgId" : "0", + "equipmentId" : "VL1", + "x" : 379.5, + "y" : -897.76 + }, { + "svgId" : "2", + "equipmentId" : "VL10", + "x" : -586.21, + "y" : 325.09 + }, { + "svgId" : "4", + "equipmentId" : "VL11", + "x" : -781.48, + "y" : -92.63 + }, { + "svgId" : "6", + "equipmentId" : "VL12", + "x" : -156.95, + "y" : -227.74 + }, { + "svgId" : "8", + "equipmentId" : "VL13", + "x" : -299.94, + "y" : 73.32 + }, { + "svgId" : "10", + "equipmentId" : "VL14", + "x" : -202.47, + "y" : 556.41 + }, { + "svgId" : "12", + "equipmentId" : "VL2", + "x" : 556.21, + "y" : -541.57 + }, { + "svgId" : "14", + "equipmentId" : "VL3", + "x" : 844.8, + "y" : -305.76 + }, { + "svgId" : "16", + "equipmentId" : "VL4", + "x" : 459.93, + "y" : -101.51 + }, { + "svgId" : "18", + "equipmentId" : "VL5", + "x" : 175.68, + "y" : -542.18 + }, { + "svgId" : "20", + "equipmentId" : "VL6", + "x" : -404.28, + "y" : -368.04 + }, { + "svgId" : "22", + "equipmentId" : "VL7", + "x" : 526.92, + "y" : 376.56 + }, { + "svgId" : "24", + "equipmentId" : "VL8", + "x" : 807.02, + "y" : 692.3 + }, { + "svgId" : "26", + "equipmentId" : "VL9", + "x" : 88.08, + "y" : 340.05 + } ], + "edges" : [ { + "svgId" : "28", + "equipmentId" : "L1-2-1", + "node1" : "0", + "node2" : "12", + "busNode1" : "1", + "busNode2" : "13", + "type" : "LineEdge" + }, { + "svgId" : "29", + "equipmentId" : "L1-5-1", + "node1" : "0", + "node2" : "18", + "busNode1" : "1", + "busNode2" : "19", + "type" : "LineEdge" + }, { + "svgId" : "30", + "equipmentId" : "L9-10-1", + "node1" : "26", + "node2" : "2", + "busNode1" : "27", + "busNode2" : "3", + "type" : "LineEdge" + }, { + "svgId" : "31", + "equipmentId" : "L10-11-1", + "node1" : "2", + "node2" : "4", + "busNode1" : "3", + "busNode2" : "5", + "type" : "LineEdge" + }, { + "svgId" : "32", + "equipmentId" : "L6-11-1", + "node1" : "20", + "node2" : "4", + "busNode1" : "21", + "busNode2" : "5", + "type" : "LineEdge" + }, { + "svgId" : "33", + "equipmentId" : "L6-12-1", + "node1" : "20", + "node2" : "6", + "busNode1" : "21", + "busNode2" : "7", + "type" : "LineEdge" + }, { + "svgId" : "34", + "equipmentId" : "L12-13-1", + "node1" : "6", + "node2" : "8", + "busNode1" : "7", + "busNode2" : "9", + "type" : "LineEdge" + }, { + "svgId" : "35", + "equipmentId" : "L6-13-1", + "node1" : "20", + "node2" : "8", + "busNode1" : "21", + "busNode2" : "9", + "type" : "LineEdge" + }, { + "svgId" : "36", + "equipmentId" : "L13-14-1", + "node1" : "8", + "node2" : "10", + "busNode1" : "9", + "busNode2" : "11", + "type" : "LineEdge" + }, { + "svgId" : "37", + "equipmentId" : "L9-14-1", + "node1" : "26", + "node2" : "10", + "busNode1" : "27", + "busNode2" : "11", + "type" : "LineEdge" + }, { + "svgId" : "38", + "equipmentId" : "L2-3-1", + "node1" : "12", + "node2" : "14", + "busNode1" : "13", + "busNode2" : "15", + "type" : "LineEdge" + }, { + "svgId" : "39", + "equipmentId" : "L2-4-1", + "node1" : "12", + "node2" : "16", + "busNode1" : "13", + "busNode2" : "17", + "type" : "LineEdge" + }, { + "svgId" : "40", + "equipmentId" : "L2-5-1", + "node1" : "12", + "node2" : "18", + "busNode1" : "13", + "busNode2" : "19", + "type" : "LineEdge" + }, { + "svgId" : "41", + "equipmentId" : "L3-4-1", + "node1" : "14", + "node2" : "16", + "busNode1" : "15", + "busNode2" : "17", + "type" : "LineEdge" + }, { + "svgId" : "42", + "equipmentId" : "L4-5-1", + "node1" : "16", + "node2" : "18", + "busNode1" : "17", + "busNode2" : "19", + "type" : "LineEdge" + }, { + "svgId" : "43", + "equipmentId" : "T4-7-1", + "node1" : "16", + "node2" : "22", + "busNode1" : "17", + "busNode2" : "23", + "type" : "TwoWtEdge" + }, { + "svgId" : "44", + "equipmentId" : "T4-9-1", + "node1" : "16", + "node2" : "26", + "busNode1" : "17", + "busNode2" : "27", + "type" : "TwoWtEdge" + }, { + "svgId" : "45", + "equipmentId" : "T5-6-1", + "node1" : "18", + "node2" : "20", + "busNode1" : "19", + "busNode2" : "21", + "type" : "TwoWtEdge" + }, { + "svgId" : "46", + "equipmentId" : "L7-8-1", + "node1" : "22", + "node2" : "24", + "busNode1" : "23", + "busNode2" : "25", + "type" : "LineEdge" + }, { + "svgId" : "47", + "equipmentId" : "L7-9-1", + "node1" : "22", + "node2" : "26", + "busNode1" : "23", + "busNode2" : "27", + "type" : "LineEdge" + } ], + "textNodes" : [ { + "svgId" : "0-textnode", + "equipmentId" : "VL1", + "vlNode" : "0", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "2-textnode", + "equipmentId" : "VL10", + "vlNode" : "2", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "4-textnode", + "equipmentId" : "VL11", + "vlNode" : "4", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "6-textnode", + "equipmentId" : "VL12", + "vlNode" : "6", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "8-textnode", + "equipmentId" : "VL13", + "vlNode" : "8", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "10-textnode", + "equipmentId" : "VL14", + "vlNode" : "10", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "12-textnode", + "equipmentId" : "VL2", + "vlNode" : "12", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "14-textnode", + "equipmentId" : "VL3", + "vlNode" : "14", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "16-textnode", + "equipmentId" : "VL4", + "vlNode" : "16", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "18-textnode", + "equipmentId" : "VL5", + "vlNode" : "18", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "20-textnode", + "equipmentId" : "VL6", + "vlNode" : "20", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "22-textnode", + "equipmentId" : "VL7", + "vlNode" : "22", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "24-textnode", + "equipmentId" : "VL8", + "vlNode" : "24", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + }, { + "svgId" : "26-textnode", + "equipmentId" : "VL9", + "vlNode" : "26", + "shiftX" : 100.0, + "shiftY" : -40.0, + "connectionShiftX" : 100.0, + "connectionShiftY" : -15.0 + } ] +} diff --git a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java index f54e96a3c..b5763475f 100644 --- a/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java +++ b/single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/GraphMetadata.java @@ -13,12 +13,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.diagram.metadata.AbstractMetadata; import com.powsybl.sld.layout.LayoutParameters; import com.powsybl.sld.library.*; import com.powsybl.sld.model.coordinate.Direction; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -29,7 +29,7 @@ * @author Geoffroy Jamgotchian {@literal } * @author Franck Lecuyer {@literal } */ -public class GraphMetadata { +public class GraphMetadata extends AbstractMetadata { @JsonInclude(JsonInclude.Include.NON_NULL) public static class NodeMetadata { @@ -427,26 +427,6 @@ public static GraphMetadata parseJson(Reader reader) { } } - public void writeJson(Path file) { - Objects.requireNonNull(file); - try (Writer writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { - writeJson(writer); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public void writeJson(Writer writer) { - Objects.requireNonNull(writer); - ObjectMapper objectMapper = JsonUtil.createObjectMapper(); - try { - objectMapper.writerWithDefaultPrettyPrinter() - .writeValue(writer, this); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - public void addComponent(Component component) { Objects.requireNonNull(component); componentByType.put(component.getType(), component); From 1b36c7d4d4e3234bbe12f10edba49f22a128a745 Mon Sep 17 00:00:00 2001 From: "massimo.ferraro" Date: Thu, 26 Sep 2024 12:45:38 +0200 Subject: [PATCH 3/7] Remove unused parameter in NAD SvgWriter Signed-off-by: massimo.ferraro --- .../src/main/java/com/powsybl/nad/NetworkAreaDiagram.java | 3 +-- .../src/main/java/com/powsybl/nad/svg/SvgWriter.java | 6 +----- .../src/test/java/com/powsybl/nad/AbstractTest.java | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index 419ca1a31..f5512bd55 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -92,8 +92,7 @@ private static void genericDraw(Network network, Object svgObject, Object metada Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter, param.getIdProviderFactory().create()).buildGraph(); param.getLayoutFactory().create().run(graph, param.getLayoutParameters()); - SvgWriter svgWriter = new SvgWriter(param.getSvgParameters(), param.getStyleProviderFactory().create(network), param.createLabelProvider(network), - param.getLayoutParameters()); + SvgWriter svgWriter = new SvgWriter(param.getSvgParameters(), param.getStyleProviderFactory().create(network), param.createLabelProvider(network)); DiagramMetadata metadata = new DiagramMetadata(param.getLayoutParameters(), param.getSvgParameters()); if (svgObject instanceof Path svgFile) { diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java index ae5b6c0cb..b640d2c11 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java @@ -8,7 +8,6 @@ import com.powsybl.commons.exceptions.UncheckedXmlStreamException; import com.powsybl.commons.xml.XmlUtil; -import com.powsybl.nad.layout.LayoutParameters; import com.powsybl.nad.model.*; import org.apache.commons.io.output.WriterOutputStream; import org.jgrapht.alg.util.Pair; @@ -63,15 +62,12 @@ public class SvgWriter { private final StyleProvider styleProvider; private final LabelProvider labelProvider; private final EdgeRendering edgeRendering; - private final LayoutParameters layoutParameters; - public SvgWriter(SvgParameters svgParameters, StyleProvider styleProvider, LabelProvider labelProvider, - LayoutParameters layoutParameters) { + public SvgWriter(SvgParameters svgParameters, StyleProvider styleProvider, LabelProvider labelProvider) { this.svgParameters = Objects.requireNonNull(svgParameters); this.styleProvider = Objects.requireNonNull(styleProvider); this.labelProvider = Objects.requireNonNull(labelProvider); this.edgeRendering = new DefaultEdgeRendering(); - this.layoutParameters = layoutParameters; } public void writeSvg(Graph graph, Path svgFile) { diff --git a/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java b/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java index 8022580b1..9a243fd98 100644 --- a/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java +++ b/network-area-diagram/src/test/java/com/powsybl/nad/AbstractTest.java @@ -51,7 +51,7 @@ protected String generateSvgString(Network network, Predicate volt Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter).buildGraph(); new BasicForceLayout().run(graph, getLayoutParameters()); StringWriter writer = new StringWriter(); - new SvgWriter(getSvgParameters(), getStyleProvider(network), getLabelProvider(network), getLayoutParameters()).writeSvg(graph, writer); + new SvgWriter(getSvgParameters(), getStyleProvider(network), getLabelProvider(network)).writeSvg(graph, writer); String svgString = writer.toString(); if (debugSvg) { writeToHomeDir(refFilename, svgString); From 9476752c2ca8e0096ee20e0762b6115fe3fb1ffa Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 15 Oct 2024 10:18:41 +0200 Subject: [PATCH 4/7] Add missing authorship Signed-off-by: Florian Dupuy --- .../java/com/powsybl/diagram/metadata/AbstractMetadata.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java b/diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java index 13647e9f9..2948507aa 100644 --- a/diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java +++ b/diagram-util/src/main/java/com/powsybl/diagram/metadata/AbstractMetadata.java @@ -18,6 +18,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.powsybl.commons.json.JsonUtil; +/** + * @author Massimo Ferraro {@literal } + */ public abstract class AbstractMetadata { public void writeJson(Path file) { From 17a72f2a4b8068db498971192ebfcff89e997750 Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 15 Oct 2024 10:19:03 +0200 Subject: [PATCH 5/7] Clean NetworkAreaDiagram utility class Signed-off-by: Florian Dupuy --- .../com/powsybl/nad/NetworkAreaDiagram.java | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index f5512bd55..fc88da421 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -7,7 +7,7 @@ */ package com.powsybl.nad; -import com.powsybl.commons.PowsyblException; +import com.powsybl.diagram.metadata.AbstractMetadata; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.nad.build.iidm.NetworkGraphBuilder; @@ -16,6 +16,7 @@ import com.powsybl.nad.svg.SvgParameters; import com.powsybl.nad.svg.SvgWriter; import com.powsybl.nad.svg.metadata.DiagramMetadata; +import org.apache.commons.io.output.NullWriter; import java.io.IOException; import java.io.StringWriter; @@ -26,8 +27,6 @@ import java.util.Objects; import java.util.function.Predicate; -import org.apache.commons.io.output.NullWriter; - /** * @author Florian Dupuy {@literal } */ @@ -69,46 +68,48 @@ public static void draw(Network network, Writer writer, Writer metadataWriter, P } public static void draw(Network network, Path svgFile, NadParameters param, Predicate voltageLevelFilter) { + Objects.requireNonNull(network); Objects.requireNonNull(svgFile); - Path dir = svgFile.toAbsolutePath().getParent(); - String svgFileName = svgFile.getFileName().toString(); - if (!svgFileName.endsWith(".svg")) { - svgFileName = svgFileName + ".svg"; - } - Path metadataFile = dir.resolve(svgFileName.replace(".svg", "_metadata.json")); - genericDraw(network, svgFile, metadataFile, param, voltageLevelFilter); - } + Objects.requireNonNull(param); - public static void draw(Network network, Writer writer, Writer metadataWriter, NadParameters param, Predicate voltageLevelFilter) { - genericDraw(network, writer, metadataWriter, param, voltageLevelFilter); + Graph graph = getLayoutResult(network, param, voltageLevelFilter); + createSvgWriter(network, param).writeSvg(graph, svgFile); + createMetadata(graph, param).writeJson(getMetadataPath(svgFile)); } - private static void genericDraw(Network network, Object svgObject, Object metadataObject, NadParameters param, Predicate voltageLevelFilter) { + public static void draw(Network network, Writer writer, Writer metadataWriter, NadParameters param, Predicate voltageLevelFilter) { Objects.requireNonNull(network); - Objects.requireNonNull(svgObject); - Objects.requireNonNull(metadataObject); + Objects.requireNonNull(writer); + Objects.requireNonNull(metadataWriter); Objects.requireNonNull(param); - Objects.requireNonNull(voltageLevelFilter); + Graph graph = getLayoutResult(network, param, voltageLevelFilter); + createSvgWriter(network, param).writeSvg(graph, writer); + createMetadata(graph, param).writeJson(metadataWriter); + } + + private static AbstractMetadata createMetadata(Graph graph, NadParameters param) { + return new DiagramMetadata(param.getLayoutParameters(), param.getSvgParameters()).addMetadata(graph); + } + + private static Graph getLayoutResult(Network network, NadParameters param, Predicate voltageLevelFilter) { + Objects.requireNonNull(voltageLevelFilter); Graph graph = new NetworkGraphBuilder(network, voltageLevelFilter, param.getIdProviderFactory().create()).buildGraph(); param.getLayoutFactory().create().run(graph, param.getLayoutParameters()); - SvgWriter svgWriter = new SvgWriter(param.getSvgParameters(), param.getStyleProviderFactory().create(network), param.createLabelProvider(network)); - DiagramMetadata metadata = new DiagramMetadata(param.getLayoutParameters(), param.getSvgParameters()); - - if (svgObject instanceof Path svgFile) { - svgWriter.writeSvg(graph, svgFile); - } else if (svgObject instanceof Writer writer) { - svgWriter.writeSvg(graph, writer); - } else { - throw new PowsyblException("Second argument is an instance of an unexpected class"); - } - if (metadataObject instanceof Path metadataFile) { - metadata.addMetadata(graph).writeJson(metadataFile); - } else if (metadataObject instanceof Writer metadataWriter) { - metadata.addMetadata(graph).writeJson(metadataWriter); - } else { - throw new PowsyblException("Third argument is an instance of an unexpected class"); + return graph; + } + + private static SvgWriter createSvgWriter(Network network, NadParameters param) { + return new SvgWriter(param.getSvgParameters(), param.getStyleProviderFactory().create(network), param.createLabelProvider(network)); + } + + private static Path getMetadataPath(Path svgPath) { + Path dir = svgPath.toAbsolutePath().getParent(); + String svgFileName = svgPath.getFileName().toString(); + if (!svgFileName.endsWith(".svg")) { + svgFileName = svgFileName + ".svg"; } + return dir.resolve(svgFileName.replace(".svg", "_metadata.json")); } public static String drawToString(Network network, SvgParameters svgParameters) { From 5c74378fbad422f16f6e7db220da59b24f67fb2f Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 15 Oct 2024 10:19:54 +0200 Subject: [PATCH 6/7] Avoid duplication radians/degrees in SvgParameters Signed-off-by: Florian Dupuy --- .../powsybl/nad/svg/DefaultEdgeRendering.java | 8 ++-- .../com/powsybl/nad/svg/SvgParameters.java | 47 +++++++++---------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/DefaultEdgeRendering.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/DefaultEdgeRendering.java index f749a7c87..882f3c210 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/DefaultEdgeRendering.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/DefaultEdgeRendering.java @@ -86,7 +86,7 @@ private void computeMultiBranchEdgesCoordinates(Graph graph, List ed double angle = Math.atan2(dy, dx); int nbForks = edges.size(); - double forkAperture = svgParameters.getEdgesForkAperture(); + double forkAperture = Math.toRadians(svgParameters.getEdgesForkAperture()); double forkLength = svgParameters.getEdgesForkLength(); double angleStep = forkAperture / (nbForks - 1); @@ -135,7 +135,7 @@ private void loopEdgesHalfLayout(Graph graph, VoltageLevelNode node, SvgParamete BranchEdge edge, BranchEdge.Side side, double angle, Point middle) { int sideSign = side == BranchEdge.Side.ONE ? -1 : 1; - double startAngle = angle + sideSign * svgParameters.getLoopEdgesAperture() / 2; + double startAngle = angle + sideSign * Math.toRadians(svgParameters.getLoopEdgesAperture() / 2); double radius = svgParameters.getTransformerCircleRadius(); double controlsDist = svgParameters.getLoopControlDistance(); boolean isTransformer = edge.isTransformerEdge(); @@ -161,7 +161,7 @@ private List computeLoopAngles(Graph graph, List loopEdges, List loopAngles = new ArrayList<>(); if (!anglesOtherEdges.isEmpty()) { anglesOtherEdges.add(anglesOtherEdges.get(0) + 2 * Math.PI); - double apertureWithMargin = svgParameters.getLoopEdgesAperture() * 1.2; + double apertureWithMargin = Math.toRadians(svgParameters.getLoopEdgesAperture() * 1.2); double[] deltaAngles = new double[anglesOtherEdges.size() - 1]; int nbSeparatedSlots = 0; @@ -218,7 +218,7 @@ private void computeLoopAnglesWhenEnoughSharedSlotsPresent(int initNbExcessiveRe break; } int nbLoopsInDelta = Math.min(nbAvailableSlots, nbExcessiveRemaining + 1); - double extraSpace = deltaAngles[iSorted] - svgParameters.getLoopEdgesAperture() * nbLoopsInDelta; // extra space without margins + double extraSpace = deltaAngles[iSorted] - Math.toRadians(svgParameters.getLoopEdgesAperture()) * nbLoopsInDelta; // extra space without margins double intraSpace = extraSpace / (nbLoopsInDelta + 1); // space between two loops and between non-loop edges and first/last loop double angleStep = (anglesOtherEdges.get(iSorted + 1) - anglesOtherEdges.get(iSorted) - intraSpace) / nbLoopsInDelta; double startAngle = anglesOtherEdges.get(iSorted) + intraSpace / 2 + angleStep / 2; diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java index 9d4d067be..d9d951508 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgParameters.java @@ -6,7 +6,6 @@ */ package com.powsybl.nad.svg; -import com.fasterxml.jackson.annotation.JsonGetter; import com.powsybl.diagram.util.ValueFormatter; import java.util.Locale; @@ -33,13 +32,11 @@ public class SvgParameters { private double transformerCircleRadius = 20; private double nodeHollowWidth = 15; private double edgesForkLength = 80; - private double edgesForkAperture = Math.toRadians(60); - private double edgesForkApertureDegrees = 60; + private double edgesForkAperture = 60; private double edgeStartShift = 0; private double unknownBusNodeExtraRadius = 10; private double loopDistance = 120; - private double loopEdgesAperture = Math.toRadians(60); - private double loopEdgesApertureDegrees = 60; + private double loopEdgesAperture = 60; private double loopControlDistance = 40; private boolean edgeInfoAlongEdge = true; private boolean edgeNameDisplayed = false; @@ -89,12 +86,10 @@ public SvgParameters(SvgParameters other) { this.nodeHollowWidth = other.nodeHollowWidth; this.edgesForkLength = other.edgesForkLength; this.edgesForkAperture = other.edgesForkAperture; - this.edgesForkApertureDegrees = other.edgesForkApertureDegrees; this.edgeStartShift = other.edgeStartShift; this.unknownBusNodeExtraRadius = other.unknownBusNodeExtraRadius; this.loopDistance = other.loopDistance; this.loopEdgesAperture = other.loopEdgesAperture; - this.loopEdgesApertureDegrees = other.loopEdgesApertureDegrees; this.loopControlDistance = other.loopControlDistance; this.edgeInfoAlongEdge = other.edgeInfoAlongEdge; this.edgeNameDisplayed = other.edgeNameDisplayed; @@ -244,34 +239,36 @@ public SvgParameters setNodeHollowWidth(double nodeHollowWidth) { return this; } - public double getEdgesForkAperture() { - return edgesForkAperture; - } - + /** + * Set the aperture of the forks corresponding to parallel edges + * @param edgesForkApertureDegrees the aperture in degrees + */ public SvgParameters setEdgesForkAperture(double edgesForkApertureDegrees) { - this.edgesForkAperture = Math.toRadians(edgesForkApertureDegrees); - this.edgesForkApertureDegrees = edgesForkApertureDegrees; + this.edgesForkAperture = edgesForkApertureDegrees; return this; } - @JsonGetter("edgesForkAperture") - public double getEdgesForkApertureDegrees() { - return edgesForkApertureDegrees; - } - - public double getLoopEdgesAperture() { - return loopEdgesAperture; + /** + * Return the aperture of the forks corresponding to parallel edges, in degrees. + */ + public double getEdgesForkAperture() { + return edgesForkAperture; } + /** + * Set the aperture of the loop edges + * @param loopEdgesApertureDegrees the aperture in degrees + */ public SvgParameters setLoopEdgesAperture(double loopEdgesApertureDegrees) { - this.loopEdgesAperture = Math.toRadians(loopEdgesApertureDegrees); - this.loopEdgesApertureDegrees = loopEdgesApertureDegrees; + this.loopEdgesAperture = loopEdgesApertureDegrees; return this; } - @JsonGetter("loopEdgesAperture") - public double getLoopEdgesApertureDegrees() { - return loopEdgesApertureDegrees; + /** + * Return the aperture of the loop edges, in degrees. + */ + public double getLoopEdgesAperture() { + return loopEdgesAperture; } public double getEdgesForkLength() { From a2da14b159032c918af9333edb553ada93d1f1cd Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Tue, 15 Oct 2024 10:20:36 +0200 Subject: [PATCH 7/7] Unify names java/json Signed-off-by: Florian Dupuy --- .../nad/svg/metadata/NodeMetadata.java | 22 +++++++++---------- .../nad/svg/metadata/TextNodeMetadata.java | 20 ++++++++--------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java index b61095e03..6060cbec9 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/NodeMetadata.java @@ -16,25 +16,23 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class NodeMetadata extends AbstractMetadataItem { - private final double positionX; - private final double positionY; + private final double x; + private final double y; public NodeMetadata(@JsonProperty("svgId") String svgId, @JsonProperty("equipmentId") String equipmentId, - @JsonProperty("x") double positionX, - @JsonProperty("y") double positionY) { + @JsonProperty("x") double x, + @JsonProperty("y") double y) { super(svgId, equipmentId); - this.positionX = positionX; - this.positionY = positionY; + this.x = x; + this.y = y; } - @JsonProperty("x") - public double getPositionX() { - return positionX; + public double getX() { + return x; } - @JsonProperty("y") - public double getPositionY() { - return positionY; + public double getY() { + return y; } } diff --git a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java index 94c830199..dc317f83a 100644 --- a/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java +++ b/network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/TextNodeMetadata.java @@ -17,22 +17,22 @@ public class TextNodeMetadata extends AbstractMetadataItem { private final String vlNodeId; - private final double positionShiftX; - private final double positionShiftY; + private final double shiftX; + private final double shiftY; private final double connectionShiftX; private final double connectionShiftY; public TextNodeMetadata(@JsonProperty("svgId") String svgId, @JsonProperty("equipmentId") String equipmentId, @JsonProperty("vlNode") String vlNodeId, - @JsonProperty("shiftX") double positionShiftX, - @JsonProperty("shiftY") double positionShiftY, + @JsonProperty("shiftX") double shiftX, + @JsonProperty("shiftY") double shiftY, @JsonProperty("connectionShiftX") double connectionShiftX, @JsonProperty("connectionShiftY") double connectionShiftY) { super(svgId, equipmentId); this.vlNodeId = vlNodeId; - this.positionShiftX = positionShiftX; - this.positionShiftY = positionShiftY; + this.shiftX = shiftX; + this.shiftY = shiftY; this.connectionShiftX = connectionShiftX; this.connectionShiftY = connectionShiftY; } @@ -43,13 +43,13 @@ public String getVlNodeId() { } @JsonProperty("shiftX") - public double getPositionShiftX() { - return positionShiftX; + public double getShiftX() { + return shiftX; } @JsonProperty("shiftY") - public double getPositionShiftY() { - return positionShiftY; + public double getShiftY() { + return shiftY; } @JsonProperty("connectionShiftX")