8
8
9
9
import com .powsybl .iidm .network .*;
10
10
import com .powsybl .iidm .network .extensions .BusbarSectionPosition ;
11
+ import lombok .Builder ;
11
12
import lombok .Getter ;
12
13
import lombok .Setter ;
13
14
import org .gridsuite .network .map .dto .ElementInfos ;
@@ -42,41 +43,48 @@ public static ElementInfos toData(Identifiable<?> identifiable, InfoTypeParamete
42
43
}
43
44
44
45
private static VoltageLevelTopologyInfos getTopologyInfos (VoltageLevel voltageLevel ) {
45
- VoltageLevelTopologyInfos topologyInfos = new VoltageLevelTopologyInfos ();
46
46
Map <Integer , Integer > nbSectionsPerBusbar = new HashMap <>();
47
47
List <BusBarSectionFormInfos > busbarSectionInfos = new ArrayList <>();
48
+ int maxBusbarIndex = 1 ;
49
+ int maxSectionIndex = 1 ;
50
+ boolean busbarSectionPositionFound = true ;
48
51
for (BusbarSection bbs : voltageLevel .getNodeBreakerView ().getBusbarSections ()) {
49
52
var extension = bbs .getExtension (BusbarSectionPosition .class );
50
- if (extension != null ) {
51
- if (extension .getBusbarIndex () > topologyInfos .getBusbarCount ()) {
52
- topologyInfos .setBusbarCount (extension .getBusbarIndex ());
53
- }
54
- if (extension .getSectionIndex () > topologyInfos .getSectionCount ()) {
55
- topologyInfos .setSectionCount (extension .getSectionIndex ());
56
- }
57
- nbSectionsPerBusbar .putIfAbsent (extension .getBusbarIndex (), 1 );
58
- if (extension .getSectionIndex () > nbSectionsPerBusbar .get (extension .getBusbarIndex ())) {
59
- nbSectionsPerBusbar .put (extension .getBusbarIndex (), extension .getSectionIndex ());
60
- }
61
- BusBarSectionFormInfos busbarSectionInfo = BusBarSectionFormInfos .builder ()
62
- .id (bbs .getId ())
63
- .vertPos (extension .getSectionIndex ())
64
- .horizPos (extension .getBusbarIndex ())
65
- .build ();
66
- busbarSectionInfos .add (busbarSectionInfo );
67
- } else {
68
- return new VoltageLevelTopologyInfos ();
53
+ if (extension == null ) {
54
+ busbarSectionPositionFound = false ;
55
+ break ;
69
56
}
57
+ int busbarIndex = extension .getBusbarIndex ();
58
+ int sectionIndex = extension .getSectionIndex ();
59
+ maxBusbarIndex = Math .max (maxBusbarIndex , busbarIndex );
60
+ maxSectionIndex = Math .max (maxSectionIndex , sectionIndex );
61
+ nbSectionsPerBusbar .merge (busbarIndex , sectionIndex , Math ::max );
62
+ busbarSectionInfos .add (BusBarSectionFormInfos .builder ()
63
+ .id (bbs .getId ())
64
+ .vertPos (sectionIndex )
65
+ .horizPos (busbarIndex )
66
+ .build ());
70
67
}
71
- if (nbSectionsPerBusbar .values ().stream ().anyMatch (v -> v != topologyInfos .getSectionCount ())) { // Non-symmetrical busbars (nb sections)
72
- return new VoltageLevelTopologyInfos ();
68
+ VoltageLevelTopologyInfos voltageLevelTopologyInfos = createDefaultTopologyInfosBuilder ().build ();
69
+ if (!busbarSectionPositionFound ) {
70
+ return voltageLevelTopologyInfos ;
73
71
}
74
72
75
- topologyInfos .setRetrievedBusbarSections (true );
76
- topologyInfos .setSwitchKinds (Collections .nCopies (topologyInfos .getSectionCount () - 1 , SwitchKind .DISCONNECTOR ));
77
- topologyInfos .setBusbarSections (busbarSectionInfos );
73
+ voltageLevelTopologyInfos .setBusbarSections (busbarSectionInfos );
74
+ voltageLevelTopologyInfos .setBusbarSectionPositionFound (true );
78
75
79
- return topologyInfos ;
76
+ int finalMaxSectionIndex = maxSectionIndex ;
77
+ boolean isSymmetrical = nbSectionsPerBusbar .values ()
78
+ .stream ()
79
+ .allMatch (v -> v == finalMaxSectionIndex );
80
+
81
+ if (isSymmetrical ) {
82
+ voltageLevelTopologyInfos .setBusbarCount (maxBusbarIndex );
83
+ voltageLevelTopologyInfos .setSectionCount (maxSectionIndex );
84
+ voltageLevelTopologyInfos .setRetrievedBusbarSections (true );
85
+ voltageLevelTopologyInfos .setSwitchKinds (Collections .nCopies (maxSectionIndex - 1 , SwitchKind .DISCONNECTOR ));
86
+ }
87
+ return voltageLevelTopologyInfos ;
80
88
}
81
89
82
90
static VoltageLevelFormInfos toFormInfos (Identifiable <?> identifiable ) {
@@ -97,6 +105,7 @@ static VoltageLevelFormInfos toFormInfos(Identifiable<?> identifiable) {
97
105
builder .sectionCount (vlTopologyInfos .getSectionCount ());
98
106
builder .switchKinds (vlTopologyInfos .getSwitchKinds ());
99
107
builder .isRetrievedBusbarSections (vlTopologyInfos .isRetrievedBusbarSections ());
108
+ builder .isBusbarSectionPositionFound (vlTopologyInfos .isBusbarSectionPositionFound ());
100
109
builder .busBarSectionInfos (vlTopologyInfos .getBusBarSectionInfosGrouped ());
101
110
}
102
111
@@ -133,14 +142,22 @@ static VoltageLevelTabInfos toTabInfos(Identifiable<?> identifiable) {
133
142
return builder .build ();
134
143
}
135
144
145
+ private static VoltageLevelTopologyInfos .VoltageLevelTopologyInfosBuilder createDefaultTopologyInfosBuilder () {
146
+ return VoltageLevelTopologyInfos .builder ()
147
+ .busbarCount (1 ).sectionCount (1 ).isRetrievedBusbarSections (false )
148
+ .switchKinds (List .of ()).busbarSections (List .of ()).isBusbarSectionPositionFound (false );
149
+ }
150
+
151
+ @ Builder
136
152
@ Getter
137
153
@ Setter
138
154
public static class VoltageLevelTopologyInfos {
139
- private List <BusBarSectionFormInfos > busbarSections = List .of ();
140
- private boolean isRetrievedBusbarSections = false ;
141
- private int busbarCount = 1 ;
142
- private int sectionCount = 1 ;
143
- private List <SwitchKind > switchKinds = List .of ();
155
+ private List <BusBarSectionFormInfos > busbarSections ;
156
+ private boolean isRetrievedBusbarSections ; // true if busbar sections are symmetrical
157
+ private boolean isBusbarSectionPositionFound ;
158
+ private int busbarCount ;
159
+ private int sectionCount ;
160
+ private List <SwitchKind > switchKinds ;
144
161
145
162
public Map <String , List <String >> getBusBarSectionInfosGrouped () {
146
163
return busbarSections .stream ()
0 commit comments