Skip to content

Commit

Permalink
Add notification when move connectable
Browse files Browse the repository at this point in the history
Signed-off-by: Slimane AMAR <[email protected]>
  • Loading branch information
Slimane AMAR committed Oct 2, 2024
1 parent 9436977 commit 1fd93ea
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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 <slimane.amar at rte-france.com>
*/
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 +
')';
}
}
Original file line number Diff line number Diff line change
@@ -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 <slimane.amar at rte-france.com>
*/
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 +
')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,8 +49,12 @@ private InjectionAttributes getAttributes() {
return getAttributes(getAbstractIdentifiable().getResource());
}

private VoltageLevelImpl getVoltageLevel() {
return index.getVoltageLevel(getAttributes().getVoltageLevelId()).orElseThrow(IllegalStateException::new);
}

private Resource<VoltageLevelAttributes> getVoltageLevelResource() {
return index.getVoltageLevel(getAttributes().getVoltageLevelId()).orElseThrow(IllegalStateException::new).getResource();
return getVoltageLevel().getResource();
}

private boolean isNodeBeakerTopologyKind() {
Expand Down Expand Up @@ -127,7 +128,7 @@ public void setConnectableBus(String busId) {
}
});

index.getVoltageLevel(getVoltageLevelResource().getId()).orElseThrow(AssertionError::new).invalidateCalculatedBuses();
getVoltageLevel().invalidateCalculatedBuses();
}

@Override
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ private AbstractIdentifiableImpl<?, U> getAbstractIdentifiable() {
}

private InjectionAttributes getAttributes() {
return attributesGetter.apply(getAbstractIdentifiable().getResource());
return getAttributes(getAbstractIdentifiable().getResource());
}

private InjectionAttributes getAttributes(Resource<U> resource) {
return attributesGetter.apply(resource);
}

private VoltageLevelImpl getVoltageLevel() {
return index.getVoltageLevel(getAttributes().getVoltageLevelId()).orElseThrow(IllegalStateException::new);
}

@Override
Expand Down Expand Up @@ -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();
}
}
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 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)
}
}

0 comments on commit 1fd93ea

Please sign in to comment.