Skip to content

Commit

Permalink
feat: add bus id in sld legend
Browse files Browse the repository at this point in the history
Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
LE SAULNIER Kevin committed Nov 14, 2024
1 parent 61165a0 commit 051ed0c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/main/java/com/powsybl/sld/server/CommonLabelProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.powsybl.sld.server;

import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.sld.layout.LayoutParameters;
import com.powsybl.sld.library.ComponentLibrary;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import com.powsybl.sld.svg.BusLegendInfo;
import com.powsybl.sld.svg.DefaultLabelProvider;
import com.powsybl.sld.svg.SvgParameters;

import java.util.List;
import java.util.stream.Collectors;

public class CommonLabelProvider extends DefaultLabelProvider {
public CommonLabelProvider(Network network, ComponentLibrary componentLibrary, LayoutParameters layoutParameters, SvgParameters svgParameters) {
super(network, componentLibrary, layoutParameters, svgParameters);
}

@Override
public List<BusLegendInfo> getBusLegendInfos(VoltageLevelGraph graph) {
VoltageLevel vl = network.getVoltageLevel(graph.getVoltageLevelInfos().getId());
return vl.getBusView().getBusStream()
.map(b -> new BusLegendInfo(b.getId(), List.of(
new BusLegendInfo.Caption(b.getNameOrId(), "busId"),
new BusLegendInfo.Caption(valueFormatter.formatVoltage(b.getV(), "kV"), "v"),
new BusLegendInfo.Caption(valueFormatter.formatAngleInDegrees(b.getAngle()), "angle")
)))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import com.powsybl.sld.model.nodes.EquipmentNode;
import com.powsybl.sld.model.nodes.FeederNode;
import com.powsybl.sld.model.nodes.Node;
import com.powsybl.sld.svg.DefaultLabelProvider;
import com.powsybl.sld.svg.LabelPosition;
import com.powsybl.sld.svg.LabelProviderFactory;
import com.powsybl.sld.svg.SvgParameters;
import com.powsybl.sld.svg.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,7 +29,7 @@
/**
* @author Ben Daamer ahmed<ahmed.bendaamer at rte-france.com>
*/
public class PositionDiagramLabelProvider extends DefaultLabelProvider {
public class PositionDiagramLabelProvider extends CommonLabelProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(PositionDiagramLabelProvider.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ SvgAndMetadata generateSvgAndMetadata(UUID networkUuid, String variantId, String
sldParameters.setLabelProviderFactory(PositionDiagramLabelProvider.newLabelProviderFactory(id));
} else if (diagParams.getSldDisplayMode() == SldDisplayMode.STATE_VARIABLE) {
svgParameters.setBusesLegendAdded(true);
sldParameters.setLabelProviderFactory(DefaultLabelProvider::new);
sldParameters.setLabelProviderFactory(CommonLabelProvider::new);
} else {
throw new PowsyblException(String.format("Given sld display mode %s doesn't exist", diagParams.getSldDisplayMode()));
}
Expand Down

0 comments on commit 051ed0c

Please sign in to comment.