Skip to content

Commit

Permalink
Add SVG parameters to metadata in network area diagram SVG (#618)
Browse files Browse the repository at this point in the history
Signed-off-by: massimo.ferraro <massimo.ferraro@soft.it>
  • Loading branch information
massimo-ferraro authored May 24, 2024
1 parent 71c275d commit a45c19c
Show file tree
Hide file tree
Showing 51 changed files with 368 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,27 @@ private void addMetadata(Graph graph, XMLStreamWriter writer) throws XMLStreamEx
getPrefixedId(graph.getBusGraphNode1(edge).getDiagramId()),
getPrefixedId(graph.getBusGraphNode2(edge).getDiagramId()),
edge.getType()));

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()), getFormattedValue(svgParameters.getArrowShift()),
getFormattedValue(svgParameters.getArrowLabelShift()), getFormattedValue(svgParameters.getConverterStationWidth()),
getFormattedValue(svgParameters.getVoltageLevelCircleRadius()),
getFormattedValue(svgParameters.getFictitiousVoltageLevelCircleRadius()),
getFormattedValue(svgParameters.getTransformerCircleRadius()), getFormattedValue(svgParameters.getNodeHollowWidth()),
getFormattedValue(svgParameters.getEdgesForkLength()), getFormattedValue(svgParameters.getEdgesForkAperture()),
getFormattedValue(svgParameters.getEdgeStartShift()), getFormattedValue(svgParameters.getUnknownBusNodeExtraRadius()),
getFormattedValue(svgParameters.getLoopDistance()), getFormattedValue(svgParameters.getLoopEdgesAperture()),
getFormattedValue(svgParameters.getLoopControlDistance()), String.valueOf(svgParameters.isEdgeInfoAlongEdge()),
String.valueOf(svgParameters.isEdgeNameDisplayed()), getFormattedValue(svgParameters.getInterAnnulusSpace()),
svgParameters.getSvgPrefix(), String.valueOf(svgParameters.isIdDisplayed()),
String.valueOf(svgParameters.isSubstationDescriptionDisplayed()), getFormattedValue(svgParameters.getArrowHeight()),
String.valueOf(svgParameters.isBusLegend()), String.valueOf(svgParameters.isVoltageLevelDetails()),
getFormattedValue(svgParameters.getDetailedTextNodeYShift()), svgParameters.getLanguageTag(),
String.valueOf(svgParameters.getVoltageValuePrecision()), String.valueOf(svgParameters.getPowerValuePrecision()),
String.valueOf(svgParameters.getAngleValuePrecision()), String.valueOf(svgParameters.getCurrentValuePrecision()),
svgParameters.getEdgeInfoDisplayed().name(), getFormattedValue(svgParameters.getPstArrowHeadSize()),
svgParameters.getUndefinedValueSymbol());
writer.writeStartElement(METADATA_ELEMENT_NAME);
metadata.writeXml(writer);
writer.writeEndElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public class DiagramMetadata {
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_SVG_PARAMETERS_ELEMENT_NAME = "svgParameters";

private final List<BusNodeMetadata> busNodesMetadata = new ArrayList<>();
private final List<NodeMetadata> nodesMetadata = new ArrayList<>();
private final List<EdgeMetadata> edgesMetadata = new ArrayList<>();
private SvgParametersMetadata svgParametersMetadata;

public static DiagramMetadata readFromSvg(InputStream inputStream) throws XMLStreamException {
return readFromSvg(XMLInputFactory.newDefaultFactory().createXMLStreamReader(inputStream));
Expand All @@ -49,6 +51,7 @@ public static DiagramMetadata readFromSvg(XMLStreamReader reader) throws XMLStre
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_SVG_PARAMETERS_ELEMENT_NAME -> metadata.svgParametersMetadata = new SvgParametersMetadata.Reader().read(reader);
default -> throw new PowsyblException("Unexpected element '" + token + "' in metadata");
}
})
Expand All @@ -74,6 +77,11 @@ public void writeXml(XMLStreamWriter writer) throws XMLStreamException {
writeCollection(busNodesMetadata, METADATA_BUS_NODES_ELEMENT_NAME, writer);
writeCollection(nodesMetadata, METADATA_NODES_ELEMENT_NAME, writer);
writeCollection(edgesMetadata, METADATA_EDGES_ELEMENT_NAME, writer);
if (svgParametersMetadata != null) {
svgParametersMetadata.write(writer);
} else {
SvgParametersMetadata.writeEmpty(writer);
}
writer.writeEndElement();
}

Expand Down Expand Up @@ -103,4 +111,22 @@ public void addNode(String svgId, String equipmentId, String positionX, String p
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));
}

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 detailedTextNodeYShift, 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, detailedTextNodeYShift, languageTag, voltageValuePrecision, powerValuePrecision,
angleValuePrecision, currentValuePrecision, edgeInfoDisplayed, pstArrowHeadSize, undefinedValueSymbol);
}
}
Loading

0 comments on commit a45c19c

Please sign in to comment.