diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusTopologyPointImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusTopologyPointImpl.java new file mode 100644 index 000000000..aa20a713d --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusTopologyPointImpl.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.iidm.network.BusTopologyPoint; +import com.powsybl.iidm.network.TopologyKind; + +import java.util.Objects; + +/** + * @author Slimane Amar + */ +public class BusTopologyPointImpl implements BusTopologyPoint { + + private final String voltageLevelId; + + private final String connectableBusId; + + private final boolean connected; + + public BusTopologyPointImpl(String voltageLevelId, String connectableBusId, boolean connected) { + this.voltageLevelId = Objects.requireNonNull(voltageLevelId); + this.connectableBusId = Objects.requireNonNull(connectableBusId); + this.connected = connected; + } + + @Override + public TopologyKind getTopologyKind() { + return TopologyKind.BUS_BREAKER; + } + + @Override + public String getVoltageLevelId() { + return voltageLevelId; + } + + @Override + public String getConnectableBusId() { + return connectableBusId; + } + + @Override + public boolean isConnected() { + return connected; + } + + @Override + public String toString() { + return "NodeTopologyPoint(" + + "voltageLevelId='" + voltageLevelId + '\'' + + ", connectableBusId='" + connectableBusId + '\'' + + ", connected=" + connected + + ')'; + } +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NodeTopologyPointImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NodeTopologyPointImpl.java new file mode 100644 index 000000000..078998e3c --- /dev/null +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NodeTopologyPointImpl.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.iidm.network.NodeTopologyPoint; +import com.powsybl.iidm.network.TopologyKind; + +import java.util.Objects; + +/** + * @author Slimane Amar + */ +public class NodeTopologyPointImpl implements NodeTopologyPoint { + + private final String voltageLevelId; + + private final int node; + + public NodeTopologyPointImpl(String voltageLevelId, int node) { + this.voltageLevelId = Objects.requireNonNull(voltageLevelId); + this.node = node; + } + + @Override + public TopologyKind getTopologyKind() { + return TopologyKind.NODE_BREAKER; + } + + @Override + public String getVoltageLevelId() { + return voltageLevelId; + } + + @Override + public int getNode() { + return node; + } + + @Override + public String toString() { + return "NodeTopologyPoint(" + + "voltageLevelId='" + voltageLevelId + '\'' + + ", node=" + node + + ')'; + } +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalBusBreakerViewImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalBusBreakerViewImpl.java index 0608fbeda..2ea96a8cc 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalBusBreakerViewImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalBusBreakerViewImpl.java @@ -7,10 +7,7 @@ package com.powsybl.network.store.iidm.impl; import com.powsybl.commons.PowsyblException; -import com.powsybl.iidm.network.Bus; -import com.powsybl.iidm.network.Connectable; -import com.powsybl.iidm.network.Terminal; -import com.powsybl.iidm.network.TopologyKind; +import com.powsybl.iidm.network.*; import com.powsybl.network.store.model.IdentifiableAttributes; import com.powsybl.network.store.model.InjectionAttributes; import com.powsybl.network.store.model.Resource; @@ -52,8 +49,12 @@ private InjectionAttributes getAttributes() { return getAttributes(getAbstractIdentifiable().getResource()); } + private VoltageLevelImpl getVoltageLevel() { + return index.getVoltageLevel(getAttributes().getVoltageLevelId()).orElseThrow(IllegalStateException::new); + } + private Resource getVoltageLevelResource() { - return index.getVoltageLevel(getAttributes().getVoltageLevelId()).orElseThrow(IllegalStateException::new).getResource(); + return getVoltageLevel().getResource(); } private boolean isNodeBeakerTopologyKind() { @@ -127,7 +128,7 @@ public void setConnectableBus(String busId) { } }); - index.getVoltageLevel(getVoltageLevelResource().getId()).orElseThrow(AssertionError::new).invalidateCalculatedBuses(); + getVoltageLevel().invalidateCalculatedBuses(); } @Override @@ -146,13 +147,15 @@ public void moveConnectable(String busId, boolean connected) { throw new PowsyblException("Trying to move connectable " + attributes.getResource().getId() + " to bus " + busId + " of voltage level " + bus.getVoltageLevel().getId() + ", which is a node breaker voltage level"); } + VoltageLevelImpl oldVoltageLevel = getVoltageLevel(); getAbstractIdentifiable().updateResource(res -> { - InjectionAttributes attr = attributesGetter.apply(res); + InjectionAttributes attr = getAttributes(res); attr.setConnectableBus(busId); attr.setBus(connected ? busId : null); attr.setNode(null); attr.setVoltageLevelId(voltageLevel.getId()); }); + oldVoltageLevel.invalidateCalculatedBuses(); voltageLevel.invalidateCalculatedBuses(); } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java index 565595f82..95b40ab52 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalImpl.java @@ -42,8 +42,22 @@ public TerminalImpl(NetworkObjectIndex index, Connectable connectable, Functi this.index = index; this.connectable = connectable; this.attributesGetter = attributesGetter; - nodeBreakerView = new TerminalNodeBreakerViewImpl<>(index, connectable, attributesGetter); - busBreakerView = new TerminalBusBreakerViewImpl<>(index, connectable, attributesGetter); + nodeBreakerView = new TerminalNodeBreakerViewImpl<>(index, connectable, attributesGetter) { + @Override + public void moveConnectable(int node, String voltageLevelId) { + TopologyPoint oldTopologyPoint = TerminalImpl.this.getTopologyPoint(); + super.moveConnectable(node, voltageLevelId); + index.notifyUpdate(connectable, "moveConnectable", oldTopologyPoint, TerminalImpl.this.getTopologyPoint()); + } + }; + busBreakerView = new TerminalBusBreakerViewImpl<>(index, connectable, attributesGetter) { + @Override + public void moveConnectable(String busId, boolean connected) { + TopologyPoint oldTopologyPoint = TerminalImpl.this.getTopologyPoint(); + super.moveConnectable(busId, connected); + index.notifyUpdate(connectable, "moveConnectable", oldTopologyPoint, TerminalImpl.this.getTopologyPoint()); + } + }; busView = new TerminalBusViewImpl<>(index, connectable, attributesGetter); } @@ -55,8 +69,8 @@ protected boolean isNodeBeakerTopologyKind() { return getTopologyKind() == TopologyKind.NODE_BREAKER; } - private boolean isBusBeakerTopologyKind() { - return getTopologyKind() == TopologyKind.BUS_BREAKER; + private TopologyPoint getTopologyPoint() { + return isNodeBeakerTopologyKind() ? new NodeTopologyPointImpl(getAttributes().getVoltageLevelId(), getNodeBreakerView().getNode()) : new BusTopologyPointImpl(getAttributes().getVoltageLevelId(), getBusBreakerView().getConnectableBus().getId(), isConnected()); } @Override diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalNodeBreakerViewImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalNodeBreakerViewImpl.java index 08cb6325e..286606fbc 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalNodeBreakerViewImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TerminalNodeBreakerViewImpl.java @@ -40,7 +40,15 @@ private AbstractIdentifiableImpl getAbstractIdentifiable() { } private InjectionAttributes getAttributes() { - return attributesGetter.apply(getAbstractIdentifiable().getResource()); + return getAttributes(getAbstractIdentifiable().getResource()); + } + + private InjectionAttributes getAttributes(Resource resource) { + return attributesGetter.apply(resource); + } + + private VoltageLevelImpl getVoltageLevel() { + return index.getVoltageLevel(getAttributes().getVoltageLevelId()).orElseThrow(IllegalStateException::new); } @Override @@ -70,13 +78,15 @@ public void moveConnectable(int node, String voltageLevelId) { throw new ValidationException(attributes.getResource(), "an equipment (" + terminal.getConnectable().getId() + ") is already connected to node " + node + " of voltage level " + voltageLevelId); } + VoltageLevelImpl oldVoltageLevel = getVoltageLevel(); getAbstractIdentifiable().updateResource(res -> { - InjectionAttributes attr = attributesGetter.apply(res); + InjectionAttributes attr = getAttributes(res); attr.setConnectableBus(null); attr.setBus(null); attr.setNode(node); attr.setVoltageLevelId(voltageLevelId); }); + oldVoltageLevel.invalidateCalculatedBuses(); voltageLevel.invalidateCalculatedBuses(); } } diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MoveConnectableNotifTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MoveConnectableNotifTest.java index 16ef9cdd7..22b09fcb4 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MoveConnectableNotifTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MoveConnectableNotifTest.java @@ -12,13 +12,4 @@ * @author Franck Lecuyer */ public class MoveConnectableNotifTest extends AbstractMoveConnectableNotifTest { - @Override - public void nodeBreakerTest() { - // FIXME remove this test when Terminal.moveConnectable sends a notification (notifyUpdate) - } - - @Override - public void busBreakerTest() { - // FIXME remove this test when Terminal.moveConnectable sends a notification (notifyUpdate) - } }