Skip to content

Commit

Permalink
Add begin/end connect/disconnect notifications in TerminalImpl connec…
Browse files Browse the repository at this point in the history
…t/disconnect

Remove some bus changing notifications
Remove double call to opening/closing switches
Fix bad return value of getConnectingSwitches method in TerminalImpl

Signed-off-by: Franck LECUYER <[email protected]>
  • Loading branch information
FranckLecuyer committed Sep 17, 2024
1 parent b240dab commit 0c28e4d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ public String getBus() {
@Override
public void setBus(String bus) {
if (side1) {
String oldValue = attributes.getBus1();
attributes.setBus1(bus);
branch.notifyUpdate("bus1", oldValue, bus, true);
} else {
String oldValue = attributes.getBus2();
attributes.setBus2(bus);
branch.notifyUpdate("bus2", oldValue, bus, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.powsybl.network.store.iidm.impl.ConnectDisconnectUtil.closeSwitches;
import static com.powsybl.network.store.iidm.impl.ConnectDisconnectUtil.openSwitches;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class TerminalImpl<U extends IdentifiableAttributes> implements Terminal, Validable {

private static final Set<IdentifiableType> CONNECTABLE_WITH_SIDES_TYPES = Set.of(IdentifiableType.LINE, IdentifiableType.TWO_WINDINGS_TRANSFORMER, IdentifiableType.THREE_WINDINGS_TRANSFORMER);

private final NetworkObjectIndex index;

private final Connectable<?> connectable;
Expand Down Expand Up @@ -230,7 +225,7 @@ boolean getConnectingSwitches(Predicate<Switch> isSwitchOperable, Set<SwitchImpl
sw.ifPresent(switchForConnection::add);
}
});
done = true;
done = !switchForConnection.isEmpty();
}

return done;
Expand All @@ -249,9 +244,6 @@ private boolean connectNodeBreaker(Predicate<Switch> isTypeSwitchToOperate) {
return false;
}

// The switches are now closed
closeSwitches(index, switchesToClose);

return true;
}

Expand All @@ -261,12 +253,8 @@ protected void connectBusBreaker() {
a.setBus(a.getConnectableBus());

// Notification to the listeners
index.notifyUpdate(getConnectable(), "connected", index.getNetwork().getVariantManager().getWorkingVariantId(), false, true);

// Notification for branches (with sides) is made in the injection attributes adapters (setBus)
if (!CONNECTABLE_WITH_SIDES_TYPES.contains(getConnectable().getType())) {
index.notifyUpdate(getConnectable(), "bus", null, a.getConnectableBus());
}
String side = Terminal.getConnectableSide(this).map(s -> Integer.toString(s.getNum())).orElse("");
index.notifyUpdate(getConnectable(), "connected" + side, index.getNetwork().getVariantManager().getWorkingVariantId(), false, true);
});
}

Expand All @@ -284,6 +272,8 @@ public boolean connect(Predicate<Switch> isTypeSwitchToOperate) {
try {
Resource<VoltageLevelAttributes> voltageLevelResource = getVoltageLevelResource();
VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes();
boolean connectedBefore = isConnected();
index.notifyUpdate(getConnectable(), "beginConnect", index.getNetwork().getVariantManager().getWorkingVariantId(), connectedBefore, null);
if (isNodeBeakerTopologyKind()) {
if (connectNodeBreaker(isTypeSwitchToOperate)) {
done = true;
Expand All @@ -296,6 +286,9 @@ public boolean connect(Predicate<Switch> isTypeSwitchToOperate) {
}
}

boolean connectedAfter = isConnected();
index.notifyUpdate(getConnectable(), "endConnect", index.getNetwork().getVariantManager().getWorkingVariantId(), null, connectedAfter);

if (done) {
// to invalidate calculated buses
voltageLevelAttributes.setCalculatedBusesValid(false);
Expand Down Expand Up @@ -402,9 +395,6 @@ private boolean disconnectNodeBreaker(Predicate<Switch> isSwitchOpenable) {
return false;
}

// The switches are now opened
openSwitches(index, switchesToOpen);

return true;
}

Expand All @@ -416,12 +406,8 @@ protected boolean disconnectBusBreaker() {
a.setBus(null);

// Notification to the listeners
index.notifyUpdate(getConnectable(), "connected", index.getNetwork().getVariantManager().getWorkingVariantId(), true, false);

// Notification for branches (with sides) is made in the injection attributes adapters (setBus)
if (!CONNECTABLE_WITH_SIDES_TYPES.contains(getConnectable().getType())) {
index.notifyUpdate(getConnectable(), "bus", a.getConnectableBus(), null);
}
String side = Terminal.getConnectableSide(this).map(s -> Integer.toString(s.getNum())).orElse("");
index.notifyUpdate(getConnectable(), "connected" + side, index.getNetwork().getVariantManager().getWorkingVariantId(), true, false);
});
return true;
}
Expand All @@ -442,6 +428,8 @@ public boolean disconnect(Predicate<Switch> isSwitchOpenable) {
try {
Resource<VoltageLevelAttributes> voltageLevelResource = getVoltageLevelResource();
VoltageLevelAttributes voltageLevelAttributes = voltageLevelResource.getAttributes();
boolean disconnectedBefore = !isConnected();
index.notifyUpdate(getConnectable(), "beginDisconnect", index.getNetwork().getVariantManager().getWorkingVariantId(), disconnectedBefore, null);
if (isNodeBeakerTopologyKind()) {
if (disconnectNodeBreaker(isSwitchOpenable)) {
done = true;
Expand All @@ -452,6 +440,9 @@ public boolean disconnect(Predicate<Switch> isSwitchOpenable) {
}
}

boolean disconnectedAfter = !isConnected();
index.notifyUpdate(getConnectable(), "endDisconnect", index.getNetwork().getVariantManager().getWorkingVariantId(), null, disconnectedAfter);

if (done) {
// to invalidate calculated buses
voltageLevelAttributes.setCalculatedBusesValid(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public String getBus() {

@Override
public void setBus(String bus) {
String oldValue = getLegAttributes().getBus();
getLegAttributes().setBus(bus);
leg.notifyUpdate("bus", oldValue, bus);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,4 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
public class ConnectionNotificationTest extends AbstractConnectionNotificationTest {
@Override
public void busBreakerTest() {
// FIXME remove this test when we have the same update notifications as the core impl when disconnecting terminals : beginDisconnect and endDisconnect
}

@Override
public void nodeBreakerTest() {
// FIXME remove this test when we have the same update notifications as the core impl when disconnecting terminals : beginDisconnect and endDisconnect
}
}

0 comments on commit 0c28e4d

Please sign in to comment.