diff --git a/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java b/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java index 0dd93134..2f4430f4 100644 --- a/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java +++ b/src/main/java/com/powsybl/nad/NetworkAreaDiagram.java @@ -17,6 +17,8 @@ import com.powsybl.nad.layout.LayoutParameters; import com.powsybl.nad.model.Graph; import com.powsybl.nad.svg.*; +import com.powsybl.nad.svg.iidm.DefaultLabelProvider; +import com.powsybl.nad.svg.iidm.DefaultStyleProvider; import java.io.IOException; import java.io.StringWriter; @@ -56,7 +58,7 @@ public void draw(Path svgFile, SvgParameters svgParameters) { } public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters) { - draw(svgFile, svgParameters, layoutParameters, new DefaultStyleProvider()); + draw(svgFile, svgParameters, layoutParameters, new DefaultStyleProvider(network)); } public void draw(Path svgFile, SvgParameters svgParameters, LayoutParameters layoutParameters, @@ -98,7 +100,7 @@ public void draw(Writer writer, SvgParameters svgParameters) { } public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters) { - draw(writer, svgParameters, layoutParameters, new DefaultStyleProvider()); + draw(writer, svgParameters, layoutParameters, new DefaultStyleProvider(network)); } public void draw(Writer writer, SvgParameters svgParameters, LayoutParameters layoutParameters, diff --git a/src/main/java/com/powsybl/nad/build/iidm/NetworkGraphBuilder.java b/src/main/java/com/powsybl/nad/build/iidm/NetworkGraphBuilder.java index c3e39e1f..2741c79a 100644 --- a/src/main/java/com/powsybl/nad/build/iidm/NetworkGraphBuilder.java +++ b/src/main/java/com/powsybl/nad/build/iidm/NetworkGraphBuilder.java @@ -85,10 +85,12 @@ public void visitLine(Line line, Branch.Side side) { .orElseThrow(() -> new PowsyblException("Cannot add line, its voltage level is unknown")); VoltageLevelNode vlOtherNode = getOrCreateVoltageLevelNode(line.getTerminal(otherSide)); - double nominalV = vlNode.getNominalV(); - LineEdge edge = new LineEdge(idProvider.createId(line), line.getId(), line.getNameOrId(), - line.getTerminal1().isConnected(), line.getTerminal2().isConnected(), nominalV); - graph.addEdge(vlNode, vlOtherNode, edge); + BranchEdge edge = new BranchEdge(idProvider.createId(line), line.getId(), line.getNameOrId(), BranchEdge.LINE_EDGE); + if (side == Branch.Side.ONE) { + graph.addEdge(vlNode, vlOtherNode, edge); + } else { + graph.addEdge(vlOtherNode, vlNode, edge); + } } @Override @@ -103,10 +105,12 @@ public void visitTwoWindingsTransformer(TwoWindingsTransformer twt, Branch.Side .orElseThrow(() -> new PowsyblException("Cannot add two-windings transformer, its voltage level is unknown")); VoltageLevelNode vlOtherNode = getOrCreateVoltageLevelNode(twt.getTerminal(otherSide)); - AbstractBranchEdge edge = new TwoWtEdge(idProvider.createId(twt), twt.getId(), twt.getNameOrId(), - twt.getTerminal(side).isConnected(), twt.getTerminal(otherSide).isConnected(), - twt.getTerminal(side).getVoltageLevel().getNominalV(), twt.getTerminal(otherSide).getVoltageLevel().getNominalV()); - graph.addEdge(vlNode, vlOtherNode, edge); + BranchEdge edge = new BranchEdge(idProvider.createId(twt), twt.getId(), twt.getNameOrId(), BranchEdge.TWO_WT_EDGE); + if (side == Branch.Side.ONE) { + graph.addEdge(vlNode, vlOtherNode, edge); + } else { + graph.addEdge(vlOtherNode, vlNode, edge); + } } @Override @@ -136,9 +140,9 @@ public void visitThreeWindingsTransformer(ThreeWindingsTransformer twt, ThreeWin String twtId = twt.getId(); String twtName = twt.getNameOrId(); TransformerNode tn = new TransformerNode(idProvider.createId(twt), twtId, twtName); - graph.addEdge(tn, vlNode, new ThreeWtEdge(idProvider.createId(get3wtLeg(twt, side)), get3wtEquipmentId(twtId, side), twtName, twt.getTerminal(side).isConnected())); - graph.addEdge(tn, vlOtherNode1, new ThreeWtEdge(idProvider.createId(get3wtLeg(twt, otherSide1)), get3wtEquipmentId(twtId, otherSide1), twtName, twt.getTerminal(otherSide1).isConnected())); - graph.addEdge(tn, vlOtherNode2, new ThreeWtEdge(idProvider.createId(get3wtLeg(twt, otherSide2)), get3wtEquipmentId(twtId, otherSide2), twtName, twt.getTerminal(otherSide2).isConnected())); + graph.addEdge(tn, vlNode, new ThreeWtEdge(idProvider.createId(get3wtLeg(twt, side)), get3wtEquipmentId(twtId, side), twtName)); + graph.addEdge(tn, vlOtherNode1, new ThreeWtEdge(idProvider.createId(get3wtLeg(twt, otherSide1)), get3wtEquipmentId(twtId, otherSide1), twtName)); + graph.addEdge(tn, vlOtherNode2, new ThreeWtEdge(idProvider.createId(get3wtLeg(twt, otherSide2)), get3wtEquipmentId(twtId, otherSide2), twtName)); } private ThreeWindingsTransformer.Leg get3wtLeg(ThreeWindingsTransformer twt, ThreeWindingsTransformer.Side side) { diff --git a/src/main/java/com/powsybl/nad/layout/AbstractLayout.java b/src/main/java/com/powsybl/nad/layout/AbstractLayout.java index d1029cf3..d4ff85bc 100644 --- a/src/main/java/com/powsybl/nad/layout/AbstractLayout.java +++ b/src/main/java/com/powsybl/nad/layout/AbstractLayout.java @@ -27,6 +27,9 @@ private void singleEdgeLayout(Node node1, Node node2, BranchEdge edge) { Point middle = Point.createMiddlePoint(point1, point2); edge.setSide1(point1, middle); edge.setSide2(point2, middle); + if (node1 instanceof VoltageLevelNode && !((VoltageLevelNode) node1).isVisible()) { + edge.setVisible(BranchEdge.Side.ONE, false); + } if (node2 instanceof VoltageLevelNode && !((VoltageLevelNode) node2).isVisible()) { edge.setVisible(BranchEdge.Side.TWO, false); } diff --git a/src/main/java/com/powsybl/nad/model/AbstractBranchEdge.java b/src/main/java/com/powsybl/nad/model/AbstractBranchEdge.java deleted file mode 100644 index 5919470a..00000000 --- a/src/main/java/com/powsybl/nad/model/AbstractBranchEdge.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (c) 2021, 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/. - */ -package com.powsybl.nad.model; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/** - * @author Florian Dupuy - */ -public abstract class AbstractBranchEdge extends AbstractEdge implements BranchEdge { - private final boolean side1Connected; - private final boolean side2Connected; - private List line1 = Collections.emptyList(); - private List line2 = Collections.emptyList(); - private final boolean[] visible = new boolean[] {true, true}; - - protected AbstractBranchEdge(String diagramId, String equipmentId, String nameOrId, boolean side1Connected, boolean side2Connected) { - super(diagramId, equipmentId, nameOrId); - this.side1Connected = side1Connected; - this.side2Connected = side2Connected; - } - - public List getLine(Side side) { - Objects.requireNonNull(side); - return side == Side.ONE ? getSide1() : getSide2(); - } - - @Override - public List getSide1() { - return Collections.unmodifiableList(line1); - } - - @Override - public List getSide2() { - return Collections.unmodifiableList(line2); - } - - @Override - public void setSide1(Point... points) { - Arrays.stream(points).forEach(Objects::requireNonNull); - this.line1 = Arrays.asList(points); - } - - @Override - public void setSide2(Point... points) { - Arrays.stream(points).forEach(Objects::requireNonNull); - this.line2 = Arrays.asList(points); - } - - @Override - public boolean isVisible(Side side) { - Objects.requireNonNull(side); - return visible[side.ordinal()]; - } - - @Override - public void setVisible(Side side, boolean visible) { - Objects.requireNonNull(side); - this.visible[side.ordinal()] = visible; - } - - public boolean isConnected(Side side) { - Objects.requireNonNull(side); - return side == Side.ONE ? isSide1Connected() : isSide2Connected(); - } - - public boolean isSide1Connected() { - return side1Connected; - } - - public boolean isSide2Connected() { - return side2Connected; - } -} diff --git a/src/main/java/com/powsybl/nad/model/BranchEdge.java b/src/main/java/com/powsybl/nad/model/BranchEdge.java index 83b327a4..67fb97cf 100644 --- a/src/main/java/com/powsybl/nad/model/BranchEdge.java +++ b/src/main/java/com/powsybl/nad/model/BranchEdge.java @@ -6,27 +6,67 @@ */ package com.powsybl.nad.model; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Objects; /** * @author Florian Dupuy */ -public interface BranchEdge extends Edge { - enum Side { +public class BranchEdge extends AbstractEdge { + + public enum Side { ONE, TWO } - List getLine(Side side); + public static final String TWO_WT_EDGE = "TwoWtEdge"; + public static final String LINE_EDGE = "LineEdge"; + + private List line1 = Collections.emptyList(); + private List line2 = Collections.emptyList(); + private final boolean[] visible = new boolean[] {true, true}; + private final String type; + + public BranchEdge(String diagramId, String equipmentId, String nameOrId, String type) { + super(diagramId, equipmentId, nameOrId); + this.type = type; + } + + public String getType() { + return type; + } + + public List getLine(Side side) { + Objects.requireNonNull(side); + return side == Side.ONE ? getSide1() : getSide2(); + } - List getSide1(); + public List getSide1() { + return Collections.unmodifiableList(line1); + } - List getSide2(); + public List getSide2() { + return Collections.unmodifiableList(line2); + } - void setSide1(Point... points); + public void setSide1(Point... points) { + Arrays.stream(points).forEach(Objects::requireNonNull); + this.line1 = Arrays.asList(points); + } - void setSide2(Point... points); + public void setSide2(Point... points) { + Arrays.stream(points).forEach(Objects::requireNonNull); + this.line2 = Arrays.asList(points); + } - boolean isVisible(Side side); + public boolean isVisible(Side side) { + Objects.requireNonNull(side); + return visible[side.ordinal()]; + } - void setVisible(Side side, boolean visible); + public void setVisible(Side side, boolean visible) { + Objects.requireNonNull(side); + this.visible[side.ordinal()] = visible; + } } diff --git a/src/main/java/com/powsybl/nad/model/LineEdge.java b/src/main/java/com/powsybl/nad/model/LineEdge.java deleted file mode 100644 index dab64637..00000000 --- a/src/main/java/com/powsybl/nad/model/LineEdge.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.powsybl.nad.model; - -public class LineEdge extends AbstractBranchEdge { - - private final double nominalV; - - public LineEdge(String diagramId, String equipmentId, String nameOrId, boolean side1Connected, boolean side2Connected, double nominalV) { - super(diagramId, equipmentId, nameOrId, side1Connected, side2Connected); - this.nominalV = nominalV; - } - - public double getNominalV() { - return nominalV; - } -} diff --git a/src/main/java/com/powsybl/nad/model/ThreeWtEdge.java b/src/main/java/com/powsybl/nad/model/ThreeWtEdge.java index 78aadf0e..b348d40a 100644 --- a/src/main/java/com/powsybl/nad/model/ThreeWtEdge.java +++ b/src/main/java/com/powsybl/nad/model/ThreeWtEdge.java @@ -10,14 +10,8 @@ * @author Florian Dupuy */ public class ThreeWtEdge extends AbstractEdge { - private final boolean connected; - public ThreeWtEdge(String diagramId, String equipmentId, String transformerName, boolean connected) { + public ThreeWtEdge(String diagramId, String equipmentId, String transformerName) { super(diagramId, equipmentId, transformerName); - this.connected = connected; - } - - public boolean isConnected() { - return connected; } } diff --git a/src/main/java/com/powsybl/nad/model/TwoWtEdge.java b/src/main/java/com/powsybl/nad/model/TwoWtEdge.java deleted file mode 100644 index b79bafb1..00000000 --- a/src/main/java/com/powsybl/nad/model/TwoWtEdge.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.powsybl.nad.model; - -public class TwoWtEdge extends AbstractBranchEdge { - - private final double nominalV1; - private final double nominalV2; - - public TwoWtEdge(String diagramId, String equipmentId, String nameOrId, boolean side1Connected, boolean side2Connected, - double nominalV1, double nominalV2) { - super(diagramId, equipmentId, nameOrId, side1Connected, side2Connected); - this.nominalV1 = nominalV1; - this.nominalV2 = nominalV2; - } - - public double getNominalV1() { - return nominalV1; - } - - public double getNominalV2() { - return nominalV2; - } - - public double getNominalV(Side side) { - return side == Side.ONE ? nominalV1 : nominalV2; - } -} diff --git a/src/main/java/com/powsybl/nad/svg/AbstractStyleProvider.java b/src/main/java/com/powsybl/nad/svg/AbstractStyleProvider.java index 2fe255aa..f2ce0007 100644 --- a/src/main/java/com/powsybl/nad/svg/AbstractStyleProvider.java +++ b/src/main/java/com/powsybl/nad/svg/AbstractStyleProvider.java @@ -65,9 +65,10 @@ public List getNodeStyleClasses(Node node) { @Override public List getEdgeStyleClasses(Edge edge) { - if (edge instanceof LineEdge) { - return getBaseVoltageStyle(((LineEdge) edge).getNominalV()) - .map(Collections::singletonList).orElse(Collections.emptyList()); + if (edge instanceof BranchEdge) { + return getBaseVoltageStyle((BranchEdge) edge) + .map(Collections::singletonList) + .orElse(Collections.emptyList()); } return Collections.emptyList(); } @@ -76,18 +77,22 @@ public List getEdgeStyleClasses(Edge edge) { public List getSideEdgeStyleClasses(BranchEdge edge, BranchEdge.Side side) { Objects.requireNonNull(side); List result = new ArrayList<>(); - if (edge instanceof AbstractBranchEdge && !((AbstractBranchEdge) edge).isConnected(side)) { + if (isDisconnectedBranch(edge, side)) { result.add(DISCONNECTED_SIDE_EDGE_CLASS); } - if (edge instanceof TwoWtEdge) { - getBaseVoltageStyle(((TwoWtEdge) edge).getNominalV(side)).ifPresent(result::add); - } + getBaseVoltageStyle(edge, side).ifPresent(result::add); return result; } - private Optional getBaseVoltageStyle(double nominalV) { + protected abstract boolean isDisconnectedBranch(BranchEdge edge, BranchEdge.Side side); + + protected abstract Optional getBaseVoltageStyle(BranchEdge edge); + + protected abstract Optional getBaseVoltageStyle(BranchEdge edge, BranchEdge.Side side); + + protected Optional getBaseVoltageStyle(double nominalV) { return baseVoltagesConfig.getBaseVoltageName(nominalV, baseVoltagesConfig.getDefaultProfile()) - .map(bvName -> CLASSES_PREFIX + bvName); + .map(bvName -> CLASSES_PREFIX + bvName); } } diff --git a/src/main/java/com/powsybl/nad/svg/DefaultStyleProvider.java b/src/main/java/com/powsybl/nad/svg/DefaultStyleProvider.java deleted file mode 100644 index fdf4f1dd..00000000 --- a/src/main/java/com/powsybl/nad/svg/DefaultStyleProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (c) 2021, 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/. - */ -package com.powsybl.nad.svg; - -import com.powsybl.commons.config.BaseVoltagesConfig; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * @author Florian Dupuy - */ -public class DefaultStyleProvider extends AbstractStyleProvider { - - public DefaultStyleProvider() { - super(); - } - - public DefaultStyleProvider(BaseVoltagesConfig baseVoltageStyle) { - super(baseVoltageStyle); - } - - @Override - public List getCssFilenames() { - return Collections.singletonList("defaultStyle.css"); - } - - @Override - public List getEdgeInfoStyles(EdgeInfo info) { - List 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"); - } - info.getDirection().ifPresent(direction -> styles.add( - CLASSES_PREFIX + (direction == EdgeInfo.Direction.IN ? "state-in" : "state-out"))); - return styles; - } - -} diff --git a/src/main/java/com/powsybl/nad/svg/EdgeInfo.java b/src/main/java/com/powsybl/nad/svg/EdgeInfo.java index 2cc2f6c7..fa204216 100644 --- a/src/main/java/com/powsybl/nad/svg/EdgeInfo.java +++ b/src/main/java/com/powsybl/nad/svg/EdgeInfo.java @@ -12,8 +12,8 @@ * @author Florian Dupuy */ public class EdgeInfo { - static final String ACTIVE_POWER = "ActivePower"; - static final String REACTIVE_POWER = "ReactivePower"; + public static final String ACTIVE_POWER = "ActivePower"; + public static final String REACTIVE_POWER = "ReactivePower"; private final String infoType; private final Direction arrowDirection; diff --git a/src/main/java/com/powsybl/nad/svg/SvgWriter.java b/src/main/java/com/powsybl/nad/svg/SvgWriter.java index fa417afd..5a245b1b 100644 --- a/src/main/java/com/powsybl/nad/svg/SvgWriter.java +++ b/src/main/java/com/powsybl/nad/svg/SvgWriter.java @@ -122,7 +122,7 @@ private void drawBranchEdges(Graph graph, XMLStreamWriter writer) throws XMLStre private void drawHalfEdge(Graph graph, XMLStreamWriter writer, BranchEdge edge, BranchEdge.Side side) throws XMLStreamException { // the half edge is only drawn if visible, but if the edge is a TwoWtEdge, the transformer is still drawn - if (!edge.isVisible(side) && !(edge instanceof TwoWtEdge)) { + if (!edge.isVisible(side) && !(edge.getType().equals(BranchEdge.TWO_WT_EDGE))) { return; } writer.writeStartElement(GROUP_ELEMENT_NAME); @@ -136,7 +136,7 @@ private void drawHalfEdge(Graph graph, XMLStreamWriter writer, BranchEdge edge, writer.writeAttribute("points", lineFormatted); drawEdgeInfo(writer, edge, side, labelProvider.getEdgeInfos(graph, edge, side)); } - if (edge instanceof TwoWtEdge) { + if (edge.getType().equals(BranchEdge.TWO_WT_EDGE)) { drawTransformer(writer, half); } writer.writeEndElement(); diff --git a/src/main/java/com/powsybl/nad/svg/DefaultLabelProvider.java b/src/main/java/com/powsybl/nad/svg/iidm/DefaultLabelProvider.java similarity index 93% rename from src/main/java/com/powsybl/nad/svg/DefaultLabelProvider.java rename to src/main/java/com/powsybl/nad/svg/iidm/DefaultLabelProvider.java index c9f42f3e..50feffd2 100644 --- a/src/main/java/com/powsybl/nad/svg/DefaultLabelProvider.java +++ b/src/main/java/com/powsybl/nad/svg/iidm/DefaultLabelProvider.java @@ -4,11 +4,13 @@ * 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/. */ -package com.powsybl.nad.svg; +package com.powsybl.nad.svg.iidm; import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; import com.powsybl.nad.model.*; +import com.powsybl.nad.svg.EdgeInfo; +import com.powsybl.nad.svg.LabelProvider; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/com/powsybl/nad/svg/iidm/DefaultStyleProvider.java b/src/main/java/com/powsybl/nad/svg/iidm/DefaultStyleProvider.java new file mode 100644 index 00000000..2b4eb501 --- /dev/null +++ b/src/main/java/com/powsybl/nad/svg/iidm/DefaultStyleProvider.java @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2021, 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/. + */ +package com.powsybl.nad.svg.iidm; + +import com.powsybl.commons.config.BaseVoltagesConfig; +import com.powsybl.iidm.network.*; +import com.powsybl.nad.model.BranchEdge; +import com.powsybl.nad.svg.AbstractStyleProvider; +import com.powsybl.nad.svg.EdgeInfo; + +import java.util.*; + +/** + * @author Florian Dupuy + */ +public class DefaultStyleProvider extends AbstractStyleProvider { + + private final Network network; + + public DefaultStyleProvider(Network network) { + super(); + this.network = network; + } + + public DefaultStyleProvider(Network network, BaseVoltagesConfig baseVoltageStyle) { + super(baseVoltageStyle); + this.network = network; + } + + @Override + public List getCssFilenames() { + return Collections.singletonList("defaultStyle.css"); + } + + @Override + public List getEdgeInfoStyles(EdgeInfo info) { + List 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"); + } + info.getDirection().ifPresent(direction -> styles.add( + CLASSES_PREFIX + (direction == EdgeInfo.Direction.IN ? "state-in" : "state-out"))); + return styles; + } + + @Override + protected boolean isDisconnectedBranch(BranchEdge edge, BranchEdge.Side side) { + Branch b = network.getBranch(edge.getEquipmentId()); + Terminal terminal = b.getTerminal(edgeSideToIidmSide(side)); + return terminal == null || !terminal.isConnected(); + } + + @Override + protected Optional getBaseVoltageStyle(BranchEdge edge) { + if (edge.getType().equals(BranchEdge.LINE_EDGE)) { + Branch branch = network.getBranch(edge.getEquipmentId()); + double nominalVoltage = 0; + if (branch.getTerminal1() != null) { + nominalVoltage = branch.getTerminal1().getVoltageLevel().getNominalV(); + } else if (branch.getTerminal2() != null) { + nominalVoltage = branch.getTerminal2().getVoltageLevel().getNominalV(); + } + return getBaseVoltageStyle(nominalVoltage); + } + return Optional.empty(); + } + + @Override + protected Optional getBaseVoltageStyle(BranchEdge edge, BranchEdge.Side side) { + if (edge.getType().equals(BranchEdge.TWO_WT_EDGE)) { + Branch branch = network.getBranch(edge.getEquipmentId()); + Terminal terminal = branch.getTerminal(edgeSideToIidmSide(side)); + double nominalVoltage = terminal == null ? 0 : terminal.getVoltageLevel().getNominalV(); + return getBaseVoltageStyle(nominalVoltage); + } + return Optional.empty(); + } + + private Branch.Side edgeSideToIidmSide(BranchEdge.Side side) { + return Objects.requireNonNull(side) == BranchEdge.Side.ONE ? Branch.Side.ONE : Branch.Side.TWO; + } +} diff --git a/src/test/java/com/powsybl/nad/AbstractTest.java b/src/test/java/com/powsybl/nad/AbstractTest.java index 9ca9814b..adf61565 100644 --- a/src/test/java/com/powsybl/nad/AbstractTest.java +++ b/src/test/java/com/powsybl/nad/AbstractTest.java @@ -36,7 +36,7 @@ public abstract class AbstractTest { protected abstract SvgParameters getSvgParameters(); - protected abstract StyleProvider getStyleProvider(); + protected abstract StyleProvider getStyleProvider(Network network); protected abstract LabelProvider getLabelProvider(Network network); @@ -48,7 +48,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(), getLabelProvider(network)).writeSvg(graph, writer); + new SvgWriter(getSvgParameters(), getStyleProvider(network), getLabelProvider(network)).writeSvg(graph, writer); String svgString = writer.toString(); if (debugSvg) { writeToHomeDir(refFilename, svgString); diff --git a/src/test/java/com/powsybl/nad/SvgWriterTest.java b/src/test/java/com/powsybl/nad/SvgWriterTest.java index 35775794..07bddae4 100644 --- a/src/test/java/com/powsybl/nad/SvgWriterTest.java +++ b/src/test/java/com/powsybl/nad/SvgWriterTest.java @@ -14,6 +14,8 @@ import com.powsybl.nad.build.iidm.VoltageLevelFilter; import com.powsybl.nad.layout.LayoutParameters; import com.powsybl.nad.svg.*; +import com.powsybl.nad.svg.iidm.DefaultLabelProvider; +import com.powsybl.nad.svg.iidm.DefaultStyleProvider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,8 +47,8 @@ protected SvgParameters getSvgParameters() { } @Override - protected StyleProvider getStyleProvider() { - return new DefaultStyleProvider(); + protected StyleProvider getStyleProvider(Network network) { + return new DefaultStyleProvider(network); } @Override diff --git a/src/test/resources/IEEE_118_bus.svg b/src/test/resources/IEEE_118_bus.svg index 411754d4..d3b35f22 100644 --- a/src/test/resources/IEEE_118_bus.svg +++ b/src/test/resources/IEEE_118_bus.svg @@ -349,44 +349,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -1111,44 +1111,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -1673,44 +1673,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -2395,44 +2395,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -4077,44 +4077,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -4239,44 +4239,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -5445,44 +5445,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + diff --git a/src/test/resources/IEEE_118_bus_partial.svg b/src/test/resources/IEEE_118_bus_partial.svg index 47a0f503..509ef05d 100644 --- a/src/test/resources/IEEE_118_bus_partial.svg +++ b/src/test/resources/IEEE_118_bus_partial.svg @@ -1315,44 +1315,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -1438,6 +1438,10 @@ + + + + @@ -1458,10 +1462,6 @@ - - - - @@ -1506,6 +1506,10 @@ + + + + @@ -1526,10 +1530,6 @@ - - - - @@ -1553,6 +1553,10 @@ + + + + @@ -1573,10 +1577,6 @@ - - - - diff --git a/src/test/resources/IEEE_24_bus.svg b/src/test/resources/IEEE_24_bus.svg index 32b471d0..ea94fe24 100644 --- a/src/test/resources/IEEE_24_bus.svg +++ b/src/test/resources/IEEE_24_bus.svg @@ -69,17 +69,17 @@ - - + + - + 0 - + @@ -88,17 +88,17 @@ - - + + - + 0 - + @@ -228,45 +228,45 @@ - - - + + + - + 0 - + 0 - + - - - + + + - + 0 - + 0 - + @@ -311,17 +311,17 @@ - - + + - + 0 - + @@ -330,17 +330,17 @@ - - + + - + 0 - + @@ -432,45 +432,45 @@ - - - + + + - + 0 - + 0 - + - - - + + + - + 0 - + 0 - + @@ -515,19 +515,19 @@ - + - - + + - + 0 - + @@ -536,17 +536,17 @@ - - + + - + 0 - + @@ -556,87 +556,87 @@ - - - + + + - + 0 - + 0 - + - - - + + + - + 0 - + 0 - + - - - + + + - + 0 - + 0 - + - - - + + + - + 0 - + 0 - + @@ -679,19 +679,19 @@ - + - - + + - + 0 - + @@ -700,17 +700,17 @@ - - + + - + 0 - + @@ -921,17 +921,17 @@ - - + + - + 0 - + @@ -940,17 +940,17 @@ - - + + - + 0 - + @@ -1001,17 +1001,17 @@ - - + + - + 0 - + @@ -1020,17 +1020,17 @@ - - + + - + 0 - + diff --git a/src/test/resources/IEEE_30_bus.svg b/src/test/resources/IEEE_30_bus.svg index ab3d1d58..3e56bfe0 100644 --- a/src/test/resources/IEEE_30_bus.svg +++ b/src/test/resources/IEEE_30_bus.svg @@ -1514,45 +1514,45 @@ - - - + + + - + 0 - + 0 - + - - - + + + - + 0 - + 0 - + diff --git a/src/test/resources/IEEE_57_bus.svg b/src/test/resources/IEEE_57_bus.svg index 3d86ceb0..6bb054ba 100644 --- a/src/test/resources/IEEE_57_bus.svg +++ b/src/test/resources/IEEE_57_bus.svg @@ -1569,44 +1569,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -2217,44 +2217,44 @@ - - + + - + 0 - + 0 - + - - + + - + 0 - + 0 - + @@ -2783,17 +2783,17 @@ - - + + - + 0 - + @@ -2802,17 +2802,17 @@ - - + + - + 0 - + @@ -2823,17 +2823,17 @@ - - + + - + 0 - + @@ -2842,17 +2842,17 @@ - - + + - + 0 - + @@ -3223,17 +3223,17 @@ - - + + - + 0 - + @@ -3242,17 +3242,17 @@ - - + + - + 0 - + diff --git a/src/test/resources/simple-eu.svg b/src/test/resources/simple-eu.svg index 78b3a340..30314e93 100644 --- a/src/test/resources/simple-eu.svg +++ b/src/test/resources/simple-eu.svg @@ -191,17 +191,17 @@ - - + + - + 0 - + @@ -210,17 +210,17 @@ - - + + - + 0 - + @@ -431,17 +431,17 @@ - - + + - + 0 - + @@ -450,17 +450,17 @@ - - + + - + 0 - +