Skip to content

Commit

Permalink
Fix missing case DanglingLine & add test (#549)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <tadam@silicom.fr>
  • Loading branch information
tadam50 authored Sep 12, 2023
1 parent 7fd4529 commit 0bd1980
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ private void visitTerminal(Terminal terminal) {
nextDepthVoltageLevels.add(voltageLevel);
}
}

@Override
public void visitDanglingLine(DanglingLine danglingLine) {
if (danglingLine.isPaired()) {
danglingLine.getTieLine().ifPresent(tieline -> visitBranch(tieline, tieline.getSide(danglingLine.getTerminal())));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.Path;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.*;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
Expand Down Expand Up @@ -100,6 +101,14 @@ private static String normalizeLineSeparator(String str) {
.replace("\r", "\n");
}

protected static String getContentFile(Path svgFile) {
try (Stream<String> lines = Files.lines(svgFile)) {
return lines.collect(Collectors.joining("\n")) + "\n";
} catch (IOException e) {
throw new RuntimeException(e);
}
}

protected LayoutParameters getLayoutParameters() {
return layoutParameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.iidm.network.Network;
import com.powsybl.nad.build.iidm.IdProvider;
import com.powsybl.nad.build.iidm.IntIdProvider;
import com.powsybl.nad.build.iidm.VoltageLevelFilter;
import com.powsybl.nad.layout.BasicForceLayoutFactory;
import com.powsybl.nad.layout.LayoutFactory;
import com.powsybl.nad.layout.LayoutParameters;
import com.powsybl.nad.svg.LabelProvider;
import com.powsybl.diagram.test.Networks;
Expand All @@ -27,11 +23,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* @author Thomas Adam <tadam at silicom.fr>
Expand Down Expand Up @@ -60,22 +52,6 @@ protected LabelProvider getLabelProvider(Network network) {
};
}

private LayoutFactory getLayoutFactory() {
return new BasicForceLayoutFactory();
}

private IdProvider getIdProvider() {
return new IntIdProvider();
}

private String getContentFile(Path svgFile) {
try (Stream<String> lines = Files.lines(svgFile)) {
return lines.collect(Collectors.joining("\n")) + "\n";
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Test
void testDrawSvg() {
Network network = Networks.createThreeVoltageLevelsFiveBuses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@
*/
package com.powsybl.nad.svg;

import com.google.common.jimfs.*;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.nad.AbstractTest;
import com.powsybl.nad.*;
import com.powsybl.nad.layout.LayoutParameters;
import com.powsybl.nad.svg.iidm.DefaultLabelProvider;
import com.powsybl.nad.svg.iidm.NominalVoltageStyleProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.nio.file.*;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Sophie Frasnedo <sophie.frasnedo at rte-france.com>
*/
class TieLineTest extends AbstractTest {

protected java.nio.file.FileSystem fileSystem;

@BeforeEach
void setup() {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
setLayoutParameters(new LayoutParameters());
setSvgParameters(new SvgParameters()
.setSvgWidthAndHeightAdded(true)
Expand All @@ -48,4 +54,16 @@ void testTieLine() {
assertEquals(toString("/tie_line.svg"), generateSvgString(network, "/tie_line.svg"));
}

@Test
void testDanglingLinePaired() {
Network network = EurostagTutorialExample1Factory.createWithTieLine();
NetworkAreaDiagram nad = new NetworkAreaDiagram(network, "VLHV1", 1);
Path svgFile = fileSystem.getPath("tie_line_filtered.svg");
nad.draw(svgFile,
getSvgParameters(),
getLayoutParameters(),
getStyleProvider(network));

assertEquals(toString("/tie_line_filtered.svg"), getContentFile(svgFile));
}
}
233 changes: 233 additions & 0 deletions network-area-diagram/src/test/resources/tie_line_filtered.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0bd1980

Please sign in to comment.