Skip to content

Commit af9381d

Browse files
authored
Merge branch 'main' into 682-separate-nominal-voltage-classes
2 parents 5d70c44 + 0855055 commit af9381d

15 files changed

Lines changed: 12 additions & 715 deletions

File tree

diagram-util/src/main/java/com/powsybl/diagram/util/forcelayout/ForceLayout.java

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Java transcription of Springy v2.8.0
33
*
44
* Copyright (c) 2010-2018 Dennis Hotson
5-
* Copyright (c) 2021 RTE (https://www.rte-france.com)
5+
* Copyright (c) 2021-2025 RTE (https://www.rte-france.com)
66
*
77
* Permission is hereby granted, free of charge, to any person
88
* obtaining a copy of this software and associated documentation
@@ -62,16 +62,13 @@ public class ForceLayout<V, E> {
6262
private static final double DEFAULT_REPULSION = 800.0;
6363
private static final double DEFAULT_FRICTION = 500;
6464
private static final double DEFAULT_MAX_SPEED = 100;
65-
/** Spring repulsion is disabled by default */
66-
private static final double DEFAULT_SPRING_REPULSION_FACTOR = 0.0;
6765

6866
private int maxSteps;
6967
private double minEnergyThreshold;
7068
private double deltaTime;
7169
private double repulsion;
7270
private double friction;
7371
private double maxSpeed;
74-
private double springRepulsionFactor;
7572
/** Initial location for some nodes */
7673
private Map<V, Point> initialPoints = Collections.emptyMap();
7774
/** The location of these nodes should not be modified by the layout */
@@ -95,7 +92,6 @@ public ForceLayout(Graph<V, E> graph) {
9592
this.repulsion = DEFAULT_REPULSION;
9693
this.friction = DEFAULT_FRICTION;
9794
this.maxSpeed = DEFAULT_MAX_SPEED;
98-
this.springRepulsionFactor = DEFAULT_SPRING_REPULSION_FACTOR;
9995
this.graph = Objects.requireNonNull(graph);
10096
}
10197

@@ -139,11 +135,6 @@ public ForceLayout<V, E> setMaxSpeed(double maxSpeed) {
139135
return this;
140136
}
141137

142-
public ForceLayout<V, E> setSpringRepulsionFactor(double springRepulsionFactor) {
143-
this.springRepulsionFactor = springRepulsionFactor;
144-
return this;
145-
}
146-
147138
public ForceLayout<V, E> setInitialPoints(Map<V, Point> initialPoints) {
148139
this.initialPoints = Objects.requireNonNull(initialPoints);
149140
return this;
@@ -210,9 +201,6 @@ public void execute() {
210201
int i;
211202
for (i = 0; i < maxSteps; i++) {
212203
applyCoulombsLawToPoints();
213-
if (springRepulsionFactor != 0.0) {
214-
applyCoulombsLawToSprings();
215-
}
216204
applyHookesLaw();
217205
if (attractToCenterForce) {
218206
attractToCenter();
@@ -255,45 +243,6 @@ private void applyCoulombsLawToPoints() {
255243
}
256244
}
257245

258-
private void applyCoulombsLawToSprings() {
259-
for (Point point : points.values()) {
260-
Vector p = point.getPosition();
261-
for (Spring spring : springs) {
262-
Point n1 = spring.getNode1();
263-
Point n2 = spring.getNode2();
264-
if (!n1.equals(point) && !n2.equals(point)) {
265-
Vector q1 = spring.getNode1().getPosition();
266-
Vector q2 = spring.getNode2().getPosition();
267-
Vector newCenter = q1.add(q2.subtract(q1).multiply(0.5));
268-
Vector force = coulombsForce(p, newCenter, repulsion * springRepulsionFactor);
269-
point.applyForce(force);
270-
n1.applyForce(force.multiply(-0.5));
271-
n2.applyForce(force.multiply(-0.5));
272-
}
273-
}
274-
}
275-
for (Spring spring : springs) {
276-
Point n1 = spring.getNode1();
277-
Point n2 = spring.getNode2();
278-
Vector p1 = spring.getNode1().getPosition();
279-
Vector p2 = spring.getNode2().getPosition();
280-
Vector newCenter = p1.add(p2.subtract(p1).multiply(0.5));
281-
for (Spring otherSpring : springs) {
282-
if (!spring.equals(otherSpring)) {
283-
// Compute the repulsion force between centers of the springs
284-
Vector op1 = otherSpring.getNode1().getPosition();
285-
Vector op2 = otherSpring.getNode2().getPosition();
286-
Vector otherCenter = op1.add(op2.subtract(op1).multiply(0.5));
287-
Vector force = coulombsForce(newCenter, otherCenter, repulsion * springRepulsionFactor);
288-
289-
// And apply it to both points of the spring
290-
n1.applyForce(force);
291-
n2.applyForce(force);
292-
}
293-
}
294-
}
295-
}
296-
297246
private void applyHookesLaw() {
298247
for (Spring spring : springs) {
299248
Point point1 = spring.getNode1();

docs/network_area_diagrams/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ NetworkAreaDiagram.draw(network, Path.of("/tmp/diagram.svg"));
4141

4242
```java
4343
SvgParameters svgParameters = new SvgParameters().setFixedHeight(1000);
44-
LayoutParameters layoutParameters = new LayoutParameters().setSpringRepulsionFactorForceLayout(0.2);
44+
LayoutParameters layoutParameters = new LayoutParameters().setMaxSteps(300);
4545
NadParameters nadParameters = new NadParameters().setSvgParameters(svgParameters).setLayoutParameters(layoutParameters);
4646
NetworkAreaDiagram.draw(network, Path.of("/tmp/diagram2.svg"), nadParameters, VoltageLevelFilter.NO_FILTER);
4747
```

network-area-diagram/src/main/java/com/powsybl/nad/layout/BasicForceLayout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
2-
* Copyright (c) 2021, RTE (http://www.rte-france.com)
2+
* Copyright (c) 2021-2025, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
67
*/
78
package com.powsybl.nad.layout;
89

@@ -44,7 +45,6 @@ protected void nodesLayout(Graph graph, LayoutParameters layoutParameters) {
4445
ForceLayout<Node, Edge> forceLayout = new ForceLayout<>(jgraphtGraph)
4546
.setAttractToCenterForce(attractToCenterForce)
4647
.setRepulsionForceFromFixedPoints(repulsionForceFromFixedPoints);
47-
forceLayout.setSpringRepulsionFactor(layoutParameters.getSpringRepulsionFactorForceLayout());
4848
forceLayout.setMaxSteps(layoutParameters.getMaxSteps());
4949

5050
setInitialPositions(forceLayout, graph);

network-area-diagram/src/main/java/com/powsybl/nad/layout/LayoutParameters.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
2-
* Copyright (c) 2021, RTE (http://www.rte-france.com)
2+
* Copyright (c) 2021-2025, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
67
*/
78
package com.powsybl.nad.layout;
89

@@ -13,7 +14,6 @@
1314
*/
1415
public class LayoutParameters {
1516
private boolean textNodesForceLayout = false;
16-
private double springRepulsionFactorForceLayout = 0.0;
1717
private Point textNodeFixedShift = new Point(100, -40);
1818
private int maxSteps = 1000;
1919
private double textNodeEdgeConnectionYShift = 25;
@@ -23,7 +23,6 @@ public LayoutParameters() {
2323

2424
public LayoutParameters(LayoutParameters other) {
2525
this.textNodesForceLayout = other.textNodesForceLayout;
26-
this.springRepulsionFactorForceLayout = other.springRepulsionFactorForceLayout;
2726
this.textNodeFixedShift = new Point(other.textNodeFixedShift.getX(), other.textNodeFixedShift.getY());
2827
this.maxSteps = other.maxSteps;
2928
this.textNodeEdgeConnectionYShift = other.textNodeEdgeConnectionYShift;
@@ -38,15 +37,6 @@ public LayoutParameters setTextNodesForceLayout(boolean textNodesForceLayout) {
3837
return this;
3938
}
4039

41-
public LayoutParameters setSpringRepulsionFactorForceLayout(double springRepulsionFactorForceLayout) {
42-
this.springRepulsionFactorForceLayout = springRepulsionFactorForceLayout;
43-
return this;
44-
}
45-
46-
public double getSpringRepulsionFactorForceLayout() {
47-
return springRepulsionFactorForceLayout;
48-
}
49-
5040
public Point getTextNodeFixedShift() {
5141
return textNodeFixedShift;
5242
}

network-area-diagram/src/test/java/com/powsybl/nad/layout/ForceLayoutTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
2-
* Copyright (c) 2022, RTE (http://www.rte-france.com)
2+
* Copyright (c) 2022-2025, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
67
*/
78
package com.powsybl.nad.layout;
89

@@ -40,13 +41,7 @@ protected LabelProvider getLabelProvider(Network network) {
4041
}
4142

4243
@Test
43-
void testDiamondNoSpringRepulsionFactor() {
44-
assertSvgEquals("/diamond-spring-repulsion-factor-0.0.svg", LayoutNetworkFactory.createDiamond());
45-
}
46-
47-
@Test
48-
void testDiamondSmallSpringRepulsionFactor() {
49-
getLayoutParameters().setSpringRepulsionFactorForceLayout(0.2);
50-
assertSvgEquals("/diamond-spring-repulsion-factor-0.2.svg", LayoutNetworkFactory.createDiamond());
44+
void testDiamond() {
45+
assertSvgEquals("/diamond-network.svg", LayoutNetworkFactory.createDiamond());
5146
}
5247
}

network-area-diagram/src/test/java/com/powsybl/nad/layout/LayoutParametersTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
2-
* Copyright (c) 2022, RTE (http://www.rte-france.com)
2+
* Copyright (c) 2022-2025, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
67
*/
78
package com.powsybl.nad.layout;
89

@@ -18,15 +19,13 @@ class LayoutParametersTest {
1819
void test() {
1920
LayoutParameters layoutParameters0 = new LayoutParameters()
2021
.setTextNodesForceLayout(true)
21-
.setSpringRepulsionFactorForceLayout(1.0)
2222
.setTextNodeFixedShift(50., 50.)
2323
.setMaxSteps(20)
2424
.setTextNodeEdgeConnectionYShift(30);
2525

2626
LayoutParameters layoutParameters1 = new LayoutParameters(layoutParameters0);
2727

2828
assertEquals(layoutParameters0.isTextNodesForceLayout(), layoutParameters1.isTextNodesForceLayout());
29-
assertEquals(layoutParameters0.getSpringRepulsionFactorForceLayout(), layoutParameters1.getSpringRepulsionFactorForceLayout(), 0);
3029
assertEquals(layoutParameters0.getTextNodeFixedShift().getX(), layoutParameters1.getTextNodeFixedShift().getX(), 0);
3130
assertEquals(layoutParameters0.getTextNodeFixedShift().getY(), layoutParameters1.getTextNodeFixedShift().getY(), 0);
3231
assertEquals(layoutParameters0.getMaxSteps(), layoutParameters1.getMaxSteps());

network-area-diagram/src/test/resources/3wt_metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"layoutParameters" : {
33
"textNodesForceLayout" : false,
4-
"springRepulsionFactorForceLayout" : 0.0,
54
"textNodeFixedShift" : {
65
"x" : 100.0,
76
"y" : -40.0

network-area-diagram/src/test/resources/IEEE_14_bus_fictitious_metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"layoutParameters" : {
33
"textNodesForceLayout" : false,
4-
"springRepulsionFactorForceLayout" : 0.0,
54
"textNodeFixedShift" : {
65
"x" : 100.0,
76
"y" : -40.0

network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter2_metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"layoutParameters" : {
33
"textNodesForceLayout" : false,
4-
"springRepulsionFactorForceLayout" : 0.0,
54
"textNodeFixedShift" : {
65
"x" : 100.0,
76
"y" : -40.0

network-area-diagram/src/test/resources/IEEE_14_bus_voltage_filter5_metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"layoutParameters" : {
33
"textNodesForceLayout" : false,
4-
"springRepulsionFactorForceLayout" : 0.0,
54
"textNodeFixedShift" : {
65
"x" : 100.0,
76
"y" : -40.0

0 commit comments

Comments
 (0)