Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add current info #505

Merged
merged 32 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fb3bb5f
feat: add current info
hquarton Mar 14, 2023
cab8d27
fix checkstyles
So-Fras Mar 16, 2023
b32f0d2
homogenize color code in FlatDesignLibrary
So-Fras Mar 16, 2023
21c69d8
update test references
So-Fras Mar 16, 2023
cad7ed4
add tests on LayoutParameters
So-Fras Mar 17, 2023
b43ce14
update test references
So-Fras Mar 17, 2023
4c3324a
add current info in test
So-Fras Mar 17, 2023
388023e
new management of edge info for network area diagram
So-Fras Mar 17, 2023
9916cea
add tests for current and reactive power edge info (that are not disp…
So-Fras Mar 20, 2023
b7ab6c7
update test references
So-Fras Mar 20, 2023
eb1e07e
fix checkstyles
So-Fras Mar 20, 2023
fa74a6e
following review : updates to address comments
So-Fras Mar 22, 2023
2a19f6e
following review: update test references
So-Fras Mar 22, 2023
de27baf
Merge branch 'main' into add-current-info
So-Fras Mar 22, 2023
e83668d
after dealing with conflicts: fix SLD tests
So-Fras Mar 22, 2023
9d4eb60
after dealing with conflicts: fix NAD tests
So-Fras Mar 22, 2023
b1769a3
remove code smells
So-Fras Mar 22, 2023
be7f416
Merge branch 'main' into add-current-info
So-Fras Mar 28, 2023
9c1c507
fix conflict resolution error and update test reference
So-Fras Mar 28, 2023
e13ad01
add specific unit test to display all kinds of feeder info
So-Fras Mar 30, 2023
7607943
fix missing style in tautologies.css + change dominant baseline for l…
So-Fras Mar 30, 2023
6ce13aa
Merge branch 'main' into add-current-info
So-Fras Mar 30, 2023
2f17d39
fix tests following merge with updates in main
So-Fras Mar 30, 2023
59e8ee0
Update TypeOfEdgeInfoTest.java
So-Fras Apr 3, 2023
374f3c5
use DefaultDiagramLabelProvider + current arrow with same direction a…
So-Fras Apr 4, 2023
bffb90c
fix checkstyle
So-Fras Apr 4, 2023
d1a6afa
removing open load flow dependency from TypeOfEdgeInfoTest
So-Fras Apr 4, 2023
394d4c1
removing open load flow dependency from other tests
So-Fras Apr 4, 2023
7cf11da
merge with main and resolve conflicts
So-Fras Apr 4, 2023
bccdfbe
update test references
So-Fras Apr 4, 2023
a2dec53
remove the connection between current arrow direction and reactive po…
So-Fras Apr 4, 2023
fdb2771
update pom to remove useless dependencies
So-Fras Apr 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.powsybl.commons.config.BaseVoltagesConfig;
import com.powsybl.nad.model.*;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -22,6 +24,8 @@
*/
public abstract class AbstractStyleProvider implements StyleProvider {

protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractStyleProvider.class);

private final BaseVoltagesConfig baseVoltagesConfig;

protected AbstractStyleProvider() {
Expand Down Expand Up @@ -87,13 +91,22 @@ public List<String> getSideEdgeStyleClasses(BranchEdge edge, BranchEdge.Side sid
@Override
public List<String> getEdgeInfoStyles(EdgeInfo info) {
List<String> styles = new LinkedList<>();
if (info.getInfoType().equals(EdgeInfo.ACTIVE_POWER)) {
styles.add(CLASSES_PREFIX + "active");
} else if (info.getInfoType().equals(EdgeInfo.REACTIVE_POWER)) {
styles.add(CLASSES_PREFIX + "reactive");
} else if (info.getInfoType().equals(EdgeInfo.CURRENT)) {
styles.add(CLASSES_PREFIX + "current");
String infoType = info.getInfoType();
switch (infoType) {
case EdgeInfo.ACTIVE_POWER:
styles.add(CLASSES_PREFIX + "active");
break;
case EdgeInfo.REACTIVE_POWER:
styles.add(CLASSES_PREFIX + "reactive");
break;
case EdgeInfo.CURRENT:
styles.add(CLASSES_PREFIX + "current");
break;
default:
LOGGER.warn("The \"{}\" type of information is not handled", infoType);
break;
}

info.getDirection().ifPresent(direction -> styles.add(
CLASSES_PREFIX + (direction == EdgeInfo.Direction.IN ? "state-in" : "state-out")));
return styles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import com.powsybl.nad.model.*;

import java.util.List;
import java.util.Optional;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface LabelProvider {
EdgeInfo getEdgeInfo(Graph graph, BranchEdge edge, BranchEdge.Side side);
Optional<EdgeInfo> getEdgeInfo(Graph graph, BranchEdge edge, BranchEdge.Side side);

EdgeInfo getEdgeInfo(Graph graph, ThreeWtEdge edge);
Optional<EdgeInfo> getEdgeInfo(Graph graph, ThreeWtEdge edge);

String getLabel(Edge edge);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,21 @@ private void drawHalfEdge(Graph graph, XMLStreamWriter writer, BranchEdge edge,
writer.writeAttribute(ID_ATTRIBUTE, getPrefixedId(edge.getDiagramId() + "." + side.getNum()));
writeStyleClasses(writer, styleProvider.getSideEdgeStyleClasses(edge, side));
if (edge.isVisible(side)) {
Optional<EdgeInfo> edgeInfo = labelProvider.getEdgeInfo(graph, edge, side);
if (!graph.isLoop(edge)) {
writer.writeEmptyElement(POLYLINE_ELEMENT_NAME);
writeStyleClasses(writer, StyleProvider.EDGE_PATH_CLASS, StyleProvider.STRETCHABLE_CLASS, StyleProvider.GLUED_CLASS + "-" + side.getNum());
writer.writeAttribute(POINTS_ATTRIBUTE, getPolylinePointsString(edge, side));
EdgeInfo edgeInfo = labelProvider.getEdgeInfo(graph, edge, side);
drawBranchEdgeInfo(graph, writer, edge, side, edgeInfo);
if (edgeInfo.isPresent()) {
drawBranchEdgeInfo(graph, writer, edge, side, edgeInfo.get());
}
} else {
writer.writeEmptyElement(PATH_ELEMENT_NAME);
writer.writeAttribute(CLASS_ATTRIBUTE, StyleProvider.EDGE_PATH_CLASS);
writer.writeAttribute(PATH_D_ATTRIBUTE, getLoopPathString(edge, side));
drawLoopEdgeInfo(writer, edge, side, labelProvider.getEdgeInfo(graph, edge, side));
if (edgeInfo.isPresent()) {
drawLoopEdgeInfo(writer, edge, side, edgeInfo.get());
}
}
}
writer.writeEndElement();
Expand Down Expand Up @@ -303,7 +307,10 @@ private void drawThreeWtEdge(Graph graph, XMLStreamWriter writer, ThreeWtEdge ed
writeStyleClasses(writer, StyleProvider.EDGE_PATH_CLASS, StyleProvider.STRETCHABLE_CLASS);
writer.writeAttribute(POINTS_ATTRIBUTE, getPolylinePointsString(edge));

drawThreeWtEdgeInfo(graph, writer, edge, labelProvider.getEdgeInfo(graph, edge));
Optional<EdgeInfo> edgeInfo = labelProvider.getEdgeInfo(graph, edge);
if (edgeInfo.isPresent()) {
drawThreeWtEdgeInfo(graph, writer, edge, edgeInfo.get());
}

writer.writeEndElement();
}
Expand Down Expand Up @@ -363,26 +370,25 @@ private void drawEdgeInfo(XMLStreamWriter writer, EdgeInfo edgeInfo, Point infoC
}

private void drawEdgeInfo(XMLStreamWriter writer, List<String> additionalStyles, EdgeInfo edgeInfo, Point infoCenter, double edgeAngle) throws XMLStreamException {
if (edgeInfo != null) {
writer.writeStartElement(GROUP_ELEMENT_NAME);
writeStyleClasses(writer, additionalStyles, StyleProvider.EDGE_INFOS_CLASS);
writer.writeAttribute(TRANSFORM_ATTRIBUTE, getTranslateString(infoCenter));

writer.writeStartElement(GROUP_ELEMENT_NAME);
writeStyleClasses(writer, styleProvider.getEdgeInfoStyles(edgeInfo));
drawInAndOutArrows(writer, edgeAngle);
Optional<String> externalLabel = edgeInfo.getExternalLabel();
if (externalLabel.isPresent()) {
drawLabel(writer, externalLabel.get(), edgeAngle, true);
}
Optional<String> internalLabel = edgeInfo.getInternalLabel();
if (internalLabel.isPresent()) {
drawLabel(writer, internalLabel.get(), edgeAngle, false);
}
writer.writeEndElement();
writer.writeStartElement(GROUP_ELEMENT_NAME);
writeStyleClasses(writer, additionalStyles, StyleProvider.EDGE_INFOS_CLASS);
writer.writeAttribute(TRANSFORM_ATTRIBUTE, getTranslateString(infoCenter));

writer.writeEndElement();
writer.writeStartElement(GROUP_ELEMENT_NAME);
writeStyleClasses(writer, styleProvider.getEdgeInfoStyles(edgeInfo));
drawInAndOutArrows(writer, edgeAngle);
Optional<String> externalLabel = edgeInfo.getExternalLabel();
if (externalLabel.isPresent()) {
drawLabel(writer, externalLabel.get(), edgeAngle, true);
}
Optional<String> internalLabel = edgeInfo.getInternalLabel();
if (internalLabel.isPresent()) {
drawLabel(writer, internalLabel.get(), edgeAngle, false);
}
writer.writeEndElement();

writer.writeEndElement();
}

private void drawInAndOutArrows(XMLStreamWriter writer, double edgeAngle) throws XMLStreamException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
Expand All @@ -34,13 +35,13 @@ public DefaultLabelProvider(Network network, SvgParameters svgParameters) {
}

@Override
public EdgeInfo getEdgeInfo(Graph graph, BranchEdge edge, BranchEdge.Side side) {
public Optional<EdgeInfo> getEdgeInfo(Graph graph, BranchEdge edge, BranchEdge.Side side) {
Terminal terminal = IidmUtils.getTerminalFromEdge(network, edge, side);
return getEdgeInfo(terminal);
}

@Override
public EdgeInfo getEdgeInfo(Graph graph, ThreeWtEdge edge) {
public Optional<EdgeInfo> getEdgeInfo(Graph graph, ThreeWtEdge edge) {
ThreeWindingsTransformer transformer = network.getThreeWindingsTransformer(edge.getEquipmentId());
if (transformer == null) {
throw new PowsyblException("Unknown three windings transformer '" + edge.getEquipmentId() + "'");
Expand All @@ -54,19 +55,19 @@ public String getLabel(Edge edge) {
return edge.getEquipmentId();
}

private EdgeInfo getEdgeInfo(Terminal terminal) {
private Optional<EdgeInfo> getEdgeInfo(Terminal terminal) {
if (terminal == null) {
return null;
return Optional.empty();
}
switch (svgParameters.getEdgeInfoDisplayed()) {
case ACTIVE_POWER:
return new EdgeInfo(EdgeInfo.ACTIVE_POWER, terminal.getP(), valueFormatter::formatPower);
return Optional.of(new EdgeInfo(EdgeInfo.ACTIVE_POWER, terminal.getP(), valueFormatter::formatPower));
case REACTIVE_POWER:
return new EdgeInfo(EdgeInfo.REACTIVE_POWER, terminal.getQ(), valueFormatter::formatPower);
return Optional.of(new EdgeInfo(EdgeInfo.REACTIVE_POWER, terminal.getQ(), valueFormatter::formatPower));
case CURRENT:
return new EdgeInfo(EdgeInfo.CURRENT, terminal.getI(), valueFormatter::formatCurrent);
return Optional.of(new EdgeInfo(EdgeInfo.CURRENT, terminal.getI(), valueFormatter::formatCurrent));
default:
return null;
return Optional.empty();
}
}

Expand Down
3 changes: 0 additions & 3 deletions network-area-diagram/src/main/resources/nominalStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
.nad-pst-arrow {stroke: #6a6a6a; stroke-width: 4; stroke-linecap: round; fill: none}
.nad-state-out .nad-arrow-in {visibility: hidden}
.nad-state-in .nad-arrow-out {visibility: hidden}
.nad-active {visibility: visible}
.nad-active path {stroke: none; fill: #546e7a}
.nad-reactive {visibility: visible}
.nad-reactive path {stroke: none; fill: #0277bd}
.nad-current {visibility: visible}
.nad-current path {stroke: none; fill: #bd4802}
.nad-text-background {flood-color: #90a4aeaa}
.nad-text-nodes {font: 25px serif; fill: black; dominant-baseline: central}
Expand Down
3 changes: 0 additions & 3 deletions network-area-diagram/src/main/resources/topologicalStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
.nad-pst-arrow {stroke: #6a6a6a; stroke-width: 4; stroke-linecap: round; fill: none}
.nad-state-out .nad-arrow-in {visibility: hidden}
.nad-state-in .nad-arrow-out {visibility: hidden}
.nad-active {visibility: visible}
.nad-active path {stroke: none; fill: #546e7a}
.nad-reactive {visibility: visible}
.nad-reactive path {stroke: none; fill: #0277bd}
.nad-current {visibility: visible}
.nad-current path {stroke: none; fill: #bd4802}
.nad-text-background {flood-color: #90a4aeaa}
.nad-text-nodes {font: 25px serif; fill: black; dominant-baseline: central}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.junit.Before;
import org.junit.Test;

import java.util.Optional;

import static org.junit.Assert.assertEquals;

/**
Expand Down Expand Up @@ -45,13 +47,13 @@ protected StyleProvider getStyleProvider(Network network) {
protected LabelProvider getLabelProvider(Network network) {
return new DefaultLabelProvider(network, getSvgParameters()) {
@Override
public EdgeInfo getEdgeInfo(Graph graph, BranchEdge edge, BranchEdge.Side side) {
return new EdgeInfo("test", EdgeInfo.Direction.OUT, internalLabel, externalLabel);
public Optional<EdgeInfo> getEdgeInfo(Graph graph, BranchEdge edge, BranchEdge.Side side) {
return Optional.of(new EdgeInfo("test", EdgeInfo.Direction.OUT, internalLabel, externalLabel));
}

@Override
public EdgeInfo getEdgeInfo(Graph graph, ThreeWtEdge edge) {
return new EdgeInfo("test", EdgeInfo.Direction.IN, internalLabel, externalLabel);
public Optional<EdgeInfo> getEdgeInfo(Graph graph, ThreeWtEdge edge) {
return Optional.of(new EdgeInfo("test", EdgeInfo.Direction.IN, internalLabel, externalLabel));
}

@Override
Expand Down
3 changes: 0 additions & 3 deletions network-area-diagram/src/test/resources/3wt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions network-area-diagram/src/test/resources/3wt_disconnected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions network-area-diagram/src/test/resources/3wt_partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions network-area-diagram/src/test/resources/IEEE_118_bus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions network-area-diagram/src/test/resources/IEEE_14_bus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading