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

Spread voltageLevels with missing position information #593

Merged
merged 8 commits into from
Apr 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ public Layout create() {
layout.setFixedNodePositions(fixedPositions);
return layout;
}

public Layout create(LayoutFactory layoutFactory) {
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
if (layoutFactory == null) {
return create();
} else {
Layout layout = layoutFactory.create();
layout.setInitialNodePositions(fixedPositions);
layout.setNodesWithFixedPosition(fixedPositions.keySet());
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
return layout;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
*/
package com.powsybl.nad.layout;

import com.powsybl.diagram.test.Networks;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.Network;
import com.powsybl.nad.build.iidm.NetworkGraphBuilder;
import com.powsybl.nad.build.iidm.VoltageLevelFilter;
import com.powsybl.nad.model.Graph;
import com.powsybl.nad.model.Point;
import com.powsybl.diagram.test.Networks;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

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

Expand Down Expand Up @@ -46,4 +48,54 @@ void testCurrentLimits() {
assertEquals(pexpected.getY(), pactual.getY(), 0);
});
}

@Test
void testMissingVL8InitialPosition() {
Network network = IeeeCdfNetworkFactory.create9();
Map<String, Point> initialPositions = new HashMap<>();
initialPositions.put("VL1", new Point(900, -900));
initialPositions.put("VL2", new Point(-300, 250));
initialPositions.put("VL3", new Point(400, 200));
initialPositions.put("VL5", new Point(500, 500));
initialPositions.put("VL6", new Point(700, 700));

Graph graph = new NetworkGraphBuilder(network, VoltageLevelFilter.NO_FILTER).buildGraph();
Layout forceLayout = new BasicFixedLayoutFactory(initialPositions).create(new BasicForceLayoutFactory());
forceLayout.run(graph, new LayoutParameters());
Map<String, Point> actual = graph.getNodePositions();

assertEquals(initialPositions.get("VL1").getX(), actual.get("VL1").getX());
assertEquals(initialPositions.get("VL1").getY(), actual.get("VL1").getY());
assertEquals(initialPositions.get("VL2").getX(), actual.get("VL2").getX());
assertEquals(initialPositions.get("VL2").getY(), actual.get("VL2").getY());
assertEquals(initialPositions.get("VL3").getX(), actual.get("VL3").getX());
assertEquals(initialPositions.get("VL3").getY(), actual.get("VL3").getY());
assertEquals(initialPositions.get("VL5").getX(), actual.get("VL5").getX());
assertEquals(initialPositions.get("VL5").getY(), actual.get("VL5").getY());
assertEquals(initialPositions.get("VL6").getX(), actual.get("VL6").getX());
assertEquals(initialPositions.get("VL6").getY(), actual.get("VL6").getY());
}

@Test
void testBasicFixedLayoutFallback() {
Network network = IeeeCdfNetworkFactory.create9();
Map<String, Point> initialPositions = new HashMap<>();
Graph graph = new NetworkGraphBuilder(network, VoltageLevelFilter.NO_FILTER).buildGraph();
Layout forceLayout = new BasicFixedLayoutFactory(initialPositions).create(null);
forceLayout.run(graph, new LayoutParameters());
Map<String, Point> actual = graph.getNodePositions();

assertEquals(0, actual.get("VL1").getX());
assertEquals(0, actual.get("VL1").getY());
assertEquals(0, actual.get("VL2").getX());
assertEquals(0, actual.get("VL2").getY());
assertEquals(0, actual.get("VL3").getX());
assertEquals(0, actual.get("VL3").getY());
assertEquals(0, actual.get("VL5").getX());
assertEquals(0, actual.get("VL5").getY());
assertEquals(0, actual.get("VL6").getX());
assertEquals(0, actual.get("VL6").getY());
assertEquals(0, actual.get("VL8").getX());
assertEquals(0, actual.get("VL8").getY());
}
}