Skip to content

Commit ae6fd3b

Browse files
committed
Add limit violation custom highlighting style support
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent 4fbd8e4 commit ae6fd3b

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

network-area-diagram/src/main/java/com/powsybl/nad/svg/iidm/TopologicalStyleProvider.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,55 @@
1111
import com.powsybl.iidm.network.Network;
1212
import com.powsybl.iidm.network.Terminal;
1313
import com.powsybl.nad.model.*;
14-
1514
import java.util.ArrayList;
1615
import java.util.Collections;
1716
import java.util.List;
17+
import java.util.Map;
1818
import java.util.Optional;
1919

2020
/**
2121
* @author Florian Dupuy {@literal <florian.dupuy at rte-france.com>}
2222
*/
2323
public class TopologicalStyleProvider extends AbstractVoltageStyleProvider {
2424

25+
private final Map<String, String> violationStyles;
26+
2527
public TopologicalStyleProvider(Network network) {
26-
super(network);
28+
this(network, Collections.emptyMap());
2729
}
2830

2931
public TopologicalStyleProvider(Network network, BaseVoltagesConfig baseVoltageStyle) {
32+
this(network, baseVoltageStyle, Collections.emptyMap());
33+
}
34+
35+
public TopologicalStyleProvider(Network network, Map<String, String> violationStyles) {
36+
super(network);
37+
this.violationStyles = violationStyles != null ? violationStyles : Collections.emptyMap();
38+
}
39+
40+
public TopologicalStyleProvider(Network network, BaseVoltagesConfig baseVoltageStyle, Map<String, String> violationStyles) {
3041
super(network, baseVoltageStyle);
42+
this.violationStyles = violationStyles != null ? violationStyles : Collections.emptyMap();
3143
}
3244

3345
@Override
3446
public List<String> getCssFilenames() {
3547
return Collections.singletonList("topologicalStyle.css");
3648
}
3749

50+
@Override
51+
public List<String> getBranchEdgeStyleClasses(BranchEdge branchEdge) {
52+
// Check custom violations first
53+
if (!violationStyles.isEmpty()) {
54+
String customStyle = violationStyles.get(branchEdge.getEquipmentId());
55+
if (customStyle != null && !customStyle.isBlank()) {
56+
return List.of(customStyle);
57+
}
58+
}
59+
// Fallback to default overload detection
60+
return super.getBranchEdgeStyleClasses(branchEdge);
61+
}
62+
3863
@Override
3964
public List<String> getBusNodeStyleClasses(BusNode busNode) {
4065
List<String> styles = new ArrayList<>(super.getBusNodeStyleClasses(busNode));

single-line-diagram/single-line-diagram-core/src/main/java/com/powsybl/sld/svg/styles/iidm/LimitHighlightStyleProvider.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,43 @@
2222
*/
2323
public class LimitHighlightStyleProvider extends EmptyStyleProvider {
2424
private final Network network;
25+
private final Map<String, String> violationStyles;
2526

2627
public LimitHighlightStyleProvider(Network network) {
28+
this(network, Collections.emptyMap());
29+
}
30+
31+
public LimitHighlightStyleProvider(Network network, Map<String, String> violationStyles) {
2732
this.network = network;
33+
this.violationStyles = violationStyles != null ? violationStyles : Collections.emptyMap();
2834
}
2935

3036
@Override
3137
public List<String> getEdgeStyles(Graph graph, Edge edge) {
38+
// Check custom violations first
39+
if (!violationStyles.isEmpty()) {
40+
Optional<String> customStyle = getCustomViolationStyle(edge);
41+
if (customStyle.isPresent()) {
42+
return List.of(customStyle.get());
43+
}
44+
}
45+
// Fallback to default overload detection
3246
Optional<String> overloadStyle = getOverloadStyle(edge);
3347
return overloadStyle.map(Collections::singletonList).orElse(Collections.emptyList());
3448
}
3549

50+
private Optional<String> getCustomViolationStyle(Edge edge) {
51+
for (Node node : edge.getNodes()) {
52+
if (node instanceof FeederNode feederNode) {
53+
String style = violationStyles.get(feederNode.getEquipmentId());
54+
if (style != null && !style.isBlank()) {
55+
return Optional.of(style);
56+
}
57+
}
58+
}
59+
return Optional.empty();
60+
}
61+
3662
private Optional<String> getOverloadStyle(Edge edge) {
3763
List<Node> nodes = edge.getNodes();
3864
for (Node node : nodes) {

0 commit comments

Comments
 (0)