Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 86 VoltageLevelLayoutFactory customization #90

Merged
merged 8 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public String toString(TreeItem<Container<?>> c) {

private String getString(Container<?> value) {
String cNameOrId = showNames.isSelected() ? value.getNameOrId() : value.getId();
if (value instanceof Substation && hideVoltageLevels.isSelected()) {
long nbVoltageLevels = ((Substation) value).getVoltageLevelStream().count();
if (value instanceof Substation substation && hideVoltageLevels.isSelected()) {
long nbVoltageLevels = substation.getVoltageLevelStream().count();
return cNameOrId + " [" + nbVoltageLevels + "]";
}
return cNameOrId;
Expand Down Expand Up @@ -346,7 +346,7 @@ private void initSubstationsTree(Network network) {
boolean sFilterOk = testPassed(filter, s);
List<VoltageLevel> voltageLevels = s.getVoltageLevelStream()
.filter(v -> sFilterOk || testPassed(filter, v))
.collect(Collectors.toList());
.toList();
if ((sFilterOk || !voltageLevels.isEmpty()) && !hideSubstations.isSelected()) {
CheckBoxTreeItem<Container<?>> sItem = new CheckBoxTreeItem<>(s);
sItem.setIndependent(true);
Expand All @@ -365,7 +365,7 @@ private void initSubstationsTree(Network network) {
List<VoltageLevel> emptySubstationVoltageLevels = network.getVoltageLevelStream()
.filter(v -> v.getSubstation().isEmpty())
.filter(v -> testPassed(filter, v))
.collect(Collectors.toList());
.toList();
initVoltageLevelsTree(rootTreeItem, emptySubstationVoltageLevels, containersChecked);

rootTreeItem.getChildren().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@

import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
Expand Down Expand Up @@ -77,16 +75,10 @@ protected String call() {
}

private static Predicate<VoltageLevel> getVoltageLevelFilter(Network network, NetworkAreaDiagramModel model, Container<?> container) {
switch (container.getContainerType()) {
case NETWORK:
return VoltageLevelFilter.NO_FILTER;
case SUBSTATION:
List<String> vls = ((Substation) container).getVoltageLevelStream().map(VoltageLevel::getId).collect(Collectors.toList());
return VoltageLevelFilter.createVoltageLevelsDepthFilter(network, vls, model.getDepth());
case VOLTAGE_LEVEL:
return VoltageLevelFilter.createVoltageLevelDepthFilter(network, container.getId(), model.getDepth());
default:
throw new AssertionError();
}
return switch (container.getContainerType()) {
case NETWORK -> VoltageLevelFilter.NO_FILTER;
case SUBSTATION -> VoltageLevelFilter.createVoltageLevelsDepthFilter(network, ((Substation) container).getVoltageLevelStream().map(VoltageLevel::getId).toList(), model.getDepth());
case VOLTAGE_LEVEL -> VoltageLevelFilter.createVoltageLevelDepthFilter(network, container.getId(), model.getDepth());
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import com.powsybl.iidm.network.*;
import com.powsybl.sld.SingleLineDiagram;
import com.powsybl.sld.SldParameters;
import com.powsybl.sld.layout.*;
import com.powsybl.sld.svg.styles.StyleProvider;
import javafx.beans.property.StringProperty;
import javafx.beans.property.*;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -46,7 +47,8 @@ public void createDiagram(SingleLineDiagramJsHandler jsHandler,
Network network,
SingleLineDiagramModel model,
ContainerResult containerResult,
Container<?> container) {
Container<?> container,
VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) {
super.createDiagram(container, containerResult.svgContentProperty());

// JSHandler management
Expand All @@ -56,7 +58,7 @@ public void createDiagram(SingleLineDiagramJsHandler jsHandler,
sw.setOpen(!sw.isOpen());
StyleProvider styleProvider = model.getStyleProvider(network);
styleProvider.reset();
updateDiagram(network, model, containerResult, container);
updateDiagram(network, model, containerResult, container, voltageLevelLayoutFactoryCreator);
}
});
setUpListenerOnWebViewChanges(jsHandler);
Expand All @@ -66,13 +68,15 @@ public void createDiagram(SingleLineDiagramJsHandler jsHandler,
metadataContent.bind(containerResult.metadataContentProperty());
graphContent.bind(containerResult.jsonContentProperty());

updateDiagram(network, model, containerResult, container);
updateDiagram(network, model, containerResult, container, voltageLevelLayoutFactoryCreator);
}

public static void updateDiagram(Network network,
SingleLineDiagramModel model,
ContainerResult containerResult,
Container<?> container) {
Container<?> container,
// PositionVoltageLevelLayoutFactory
VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) {
Service<ContainerResult> sldService = new Service<>() {
@Override
protected Task<ContainerResult> createTask() {
Expand All @@ -90,7 +94,7 @@ protected ContainerResult call() {
.setComponentLibrary(model.getComponentLibrary())
.setSubstationLayoutFactory(model.getSubstationLayoutFactory())
.setStyleProviderFactory(model::getStyleProvider)
.setVoltageLevelLayoutFactoryCreator(model.getVoltageLevelLayoutFactoryCreator());
.setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

SingleLineDiagram.draw(network, container.getId(),
svgWriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

import com.powsybl.diagram.viewer.common.DiagramModel;
import com.powsybl.iidm.network.Network;
import com.powsybl.sld.cgmes.dl.iidm.extensions.NetworkDiagramData;
import com.powsybl.sld.cgmes.layout.CgmesSubstationLayoutFactory;
import com.powsybl.sld.cgmes.layout.CgmesVoltageLevelLayoutFactory;
import com.powsybl.sld.cgmes.dl.iidm.extensions.*;
import com.powsybl.sld.cgmes.layout.*;
import com.powsybl.sld.layout.*;

import com.powsybl.sld.layout.positionbyclustering.PositionByClustering;
import com.powsybl.sld.library.ComponentLibrary;
import com.powsybl.sld.svg.SvgParameters;
import com.powsybl.sld.svg.styles.*;
Expand All @@ -32,6 +30,21 @@
*/
public class SingleLineDiagramModel extends DiagramModel {

public enum VoltageLevelLayoutFactoryType {
POSITION_WITH_EXTENSIONS, POSITION_BY_CLUSTERING, CGMES, RANDOM, SMART;

@Override
public String toString() {
return switch (this) {
case SMART -> "'Smart' choice";
case POSITION_WITH_EXTENSIONS -> "Position with extensions";
case POSITION_BY_CLUSTERING -> "Position by clustering";
case RANDOM -> "Random";
case CGMES -> "CGMES";
};
}
}

private static final String UNKNOWN_ITEM = "???";

// LayoutParameters
Expand All @@ -53,22 +66,10 @@ public class SingleLineDiagramModel extends DiagramModel {
private final BooleanProperty highlightStyleProvider = new SimpleBooleanProperty();
private final BooleanProperty topologicalStyleProvider = new SimpleBooleanProperty();

private static final String SMART_VOLTAGELEVEL_LAYOUT = "Smart";
private static final String AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT = "Auto extensions";
private static final String AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT = "Auto without extensions Clustering";
private static final String RANDOM_VOLTAGELEVEL_LAYOUT = "Random";
private static final String CGMES_VOLTAGELEVEL_LAYOUT = "CGMES";

// VoltageLevel layout provider
private final Map<String, VoltageLevelLayoutFactoryCreator> nameToVoltageLevelLayoutFactoryCreatorMap = new TreeMap<>(); // ordered
private final ObservableList<VoltageLevelLayoutFactoryCreator> voltageLevelLayouts = FXCollections.observableArrayList();
private final ObjectProperty<VoltageLevelLayoutFactoryCreator> currentVoltageLevelLayoutFactoryCreator = new SimpleObjectProperty<>();

// Substation layout provider
private static final String HORIZONTAL_SUBSTATION_LAYOUT = "Horizontal";
private static final String VERTICAL_SUBSTATION_LAYOUT = "Vertical";
private static final String CGMES_SUBSTATION_LAYOUT = "CGMES";

// Substation layout provider
private final Map<String, SubstationLayoutFactory> nameToSubstationLayoutFactoryMap = new TreeMap<>(); // ordered
private final ObservableList<SubstationLayoutFactory> substationLayouts = FXCollections.observableArrayList();
private final ObjectProperty<SubstationLayoutFactory> currentSubstationLayoutFactory = new SimpleObjectProperty<>();
Expand All @@ -79,7 +80,6 @@ public class SingleLineDiagramModel extends DiagramModel {

public SingleLineDiagramModel(// Providers
ReadOnlyObjectProperty<ComponentLibrary> componentLibrary,
ReadOnlyObjectProperty<VoltageLevelLayoutFactoryCreator> voltageLevelLayoutFactoryCreator,
ReadOnlyObjectProperty<SubstationLayoutFactory> substationLayoutFactory,
ReadOnlyObjectProperty<String> cgmesDLDiagramName,
// Styles
Expand All @@ -90,12 +90,6 @@ public SingleLineDiagramModel(// Providers
Property<Double> animationThreshold2,
BooleanProperty highlightStyleProvider,
BooleanProperty topologicalStyleProvider,
// PositionVoltageLevelLayoutFactory
BooleanProperty stackFeeders,
BooleanProperty exceptionWhenPatternUnhandled,
BooleanProperty handleShunts,
BooleanProperty removeFictitiousNodes,
BooleanProperty substituteSingularFictitiousNodes,
// LayoutParameters
Property<Double> diagramPaddingTopBottom,
Property<Double> diagramPaddingLeftRight,
Expand Down Expand Up @@ -134,7 +128,6 @@ public SingleLineDiagramModel(// Providers

// Providers
this.currentComponentLibrary.bind(componentLibrary);
this.currentVoltageLevelLayoutFactoryCreator.bind(voltageLevelLayoutFactoryCreator);
this.currentSubstationLayoutFactory.bind(substationLayoutFactory);
this.currentCgmesDLDiagramName.bind(cgmesDLDiagramName);

Expand Down Expand Up @@ -182,25 +175,17 @@ public SingleLineDiagramModel(// Providers
}

public void initProviders() {
// VoltageLevelLayouts
nameToVoltageLevelLayoutFactoryCreatorMap.put(AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT, VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator());
nameToVoltageLevelLayoutFactoryCreatorMap.put(AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT, VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator(new PositionByClustering()));
nameToVoltageLevelLayoutFactoryCreatorMap.put(RANDOM_VOLTAGELEVEL_LAYOUT, i -> new RandomVoltageLevelLayoutFactory(500, 500));
// SubstationLayouts
nameToSubstationLayoutFactoryMap.put(HORIZONTAL_SUBSTATION_LAYOUT, new HorizontalSubstationLayoutFactory());
nameToSubstationLayoutFactoryMap.put(VERTICAL_SUBSTATION_LAYOUT, new VerticalSubstationLayoutFactory());

// Set all providers list
componentLibraries.setAll(ComponentLibrary.findAll());
substationLayouts.setAll(nameToSubstationLayoutFactoryMap.values());
voltageLevelLayouts.setAll(nameToVoltageLevelLayoutFactoryCreatorMap.values());
}

public void updateFrom(Network network) {
if (network != null) {
// VoltageLevelLayouts
nameToVoltageLevelLayoutFactoryCreatorMap.put(SMART_VOLTAGELEVEL_LAYOUT, VoltageLevelLayoutFactoryCreator.newSmartVoltageLevelLayoutFactoryCreator());
nameToVoltageLevelLayoutFactoryCreatorMap.put(CGMES_VOLTAGELEVEL_LAYOUT, CgmesVoltageLevelLayoutFactory::new);
// SubstationLayouts
nameToSubstationLayoutFactoryMap.put(CGMES_SUBSTATION_LAYOUT, new CgmesSubstationLayoutFactory(network));
// CGMES-DL names
Expand All @@ -210,9 +195,9 @@ public void updateFrom(Network network) {
cgmesDLDiagramNames.clear();
}
}

// Set all providers list
substationLayouts.setAll(nameToSubstationLayoutFactoryMap.values());
voltageLevelLayouts.setAll(nameToVoltageLevelLayoutFactoryCreatorMap.values());
}

public void addListener(ChangeListener<Object> changeListener) {
Expand Down Expand Up @@ -259,10 +244,6 @@ public StyleProvider getStyleProvider(Network network) {
return new StyleProvidersList(styles);
}

public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator() {
return currentVoltageLevelLayoutFactoryCreator.get();
}

public SubstationLayoutFactory getSubstationLayoutFactory() {
return currentSubstationLayoutFactory.get();
}
Expand All @@ -271,10 +252,6 @@ public ObservableList<ComponentLibrary> getComponentLibraries() {
return componentLibraries;
}

public ObservableList<VoltageLevelLayoutFactoryCreator> getVoltageLevelLayouts() {
return voltageLevelLayouts;
}

public ObservableList<SubstationLayoutFactory> getSubstationLayouts() {
return substationLayouts;
}
Expand Down Expand Up @@ -311,19 +288,4 @@ public SubstationLayoutFactory fromString(String item) {
}
};
}

public StringConverter<VoltageLevelLayoutFactoryCreator> getVoltageLevelLayoutFactoryCreatorStringConverter() {
return new StringConverter<>() {
@Override
public String toString(VoltageLevelLayoutFactoryCreator object) {
Optional<String> label = nameToVoltageLevelLayoutFactoryCreatorMap.keySet().stream().filter(name -> nameToVoltageLevelLayoutFactoryCreatorMap.get(name) == object).findFirst();
return label.orElse(UNKNOWN_ITEM);
}

@Override
public VoltageLevelLayoutFactoryCreator fromString(String item) {
return nameToVoltageLevelLayoutFactoryCreatorMap.get(item);
}
};
}
}
Loading
Loading