From 266a81575d239e1b431295e2b603b83b0a7bd71d Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Mon, 22 Jan 2024 16:17:45 +0100 Subject: [PATCH 1/8] Revert VoltageLevelLayoutFactoryBean Signed-off-by: Thomas ADAM --- .../sld/PositionVoltageLevelLayoutBean.java | 67 +++++++++++++ .../sld/SingleLineDiagramController.java | 2 +- .../viewer/sld/SingleLineDiagramModel.java | 84 ++++++++++------- .../sld/SingleLineDiagramViewController.java | 38 ++++---- .../sld/VoltageLevelLayoutFactoryBean.java | 93 +++++++++++++++++++ .../src/main/resources/sld/view.fxml | 2 +- 6 files changed, 233 insertions(+), 53 deletions(-) create mode 100644 diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/PositionVoltageLevelLayoutBean.java create mode 100644 diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/VoltageLevelLayoutFactoryBean.java diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/PositionVoltageLevelLayoutBean.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/PositionVoltageLevelLayoutBean.java new file mode 100644 index 0000000..4ddd950 --- /dev/null +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/PositionVoltageLevelLayoutBean.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2023, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.diagram.viewer.sld; + +import com.powsybl.sld.layout.*; +import javafx.beans.property.*; +import javafx.beans.value.*; + +/** + * @author Thomas Adam + */ +public class PositionVoltageLevelLayoutBean { + + // PositionVoltageLevelLayoutFactory + private final BooleanProperty stackFeeders = new SimpleBooleanProperty(); + + private final BooleanProperty exceptionWhenPatternUnhandled = new SimpleBooleanProperty(); + + private final BooleanProperty handleShunts = new SimpleBooleanProperty(); + + private final BooleanProperty removeFictitiousNodes = new SimpleBooleanProperty(); + + private final BooleanProperty substituteSingularFictitiousNodes = new SimpleBooleanProperty(); + + public BooleanProperty stackFeedersProperty() { + return stackFeeders; + } + + public BooleanProperty exceptionWhenPatternUnhandledProperty() { + return exceptionWhenPatternUnhandled; + } + + public BooleanProperty handleShuntsProperty() { + return handleShunts; + } + + public BooleanProperty removeFictitiousNodesProperty() { + return removeFictitiousNodes; + } + + public BooleanProperty substituteSingularFictitiousNodesProperty() { + return substituteSingularFictitiousNodes; + } + + public PositionVoltageLevelLayoutFactoryParameters getParameters() { + PositionVoltageLevelLayoutFactoryParameters parameters = new PositionVoltageLevelLayoutFactoryParameters(); + parameters.setFeederStacked(stackFeeders.get()); + parameters.setExceptionIfPatternNotHandled(exceptionWhenPatternUnhandled.get()); + parameters.setHandleShunts(handleShunts.get()); + parameters.setRemoveUnnecessaryFictitiousNodes(removeFictitiousNodes.get()); + parameters.setSubstituteSingularFictitiousByFeederNode(substituteSingularFictitiousNodes.get()); + return parameters; + } + + public void addListener(ChangeListener changeListener) { + this.stackFeeders.addListener(changeListener); + this.exceptionWhenPatternUnhandled.addListener(changeListener); + this.handleShunts.addListener(changeListener); + this.removeFictitiousNodes.addListener(changeListener); + this.substituteSingularFictitiousNodes.addListener(changeListener); + } +} diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramController.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramController.java index f57eebc..906aa85 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramController.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramController.java @@ -90,7 +90,7 @@ protected ContainerResult call() { .setComponentLibrary(model.getComponentLibrary()) .setSubstationLayoutFactory(model.getSubstationLayoutFactory()) .setStyleProviderFactory(model::getStyleProvider) - .setVoltageLevelLayoutFactoryCreator(model.getVoltageLevelLayoutFactoryCreator()); + .setVoltageLevelLayoutFactoryCreator(model.getVoltageLevelLayoutFactoryCreator(network)); SingleLineDiagram.draw(network, container.getId(), svgWriter, diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramModel.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramModel.java index 23277b0..ad11d24 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramModel.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramModel.java @@ -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.dl.iidm.extensions.*; import com.powsybl.sld.cgmes.layout.CgmesSubstationLayoutFactory; -import com.powsybl.sld.cgmes.layout.CgmesVoltageLevelLayoutFactory; 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.*; @@ -60,15 +58,12 @@ public class SingleLineDiagramModel extends DiagramModel { private static final String CGMES_VOLTAGELEVEL_LAYOUT = "CGMES"; // VoltageLevel layout provider - private final Map nameToVoltageLevelLayoutFactoryCreatorMap = new TreeMap<>(); // ordered - private final ObservableList voltageLevelLayouts = FXCollections.observableArrayList(); - private final ObjectProperty currentVoltageLevelLayoutFactoryCreator = new SimpleObjectProperty<>(); + private final VoltageLevelLayoutFactoryBean voltageLevelLayoutFactoryBean; + // 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 nameToSubstationLayoutFactoryMap = new TreeMap<>(); // ordered private final ObservableList substationLayouts = FXCollections.observableArrayList(); private final ObjectProperty currentSubstationLayoutFactory = new SimpleObjectProperty<>(); @@ -79,7 +74,7 @@ public class SingleLineDiagramModel extends DiagramModel { public SingleLineDiagramModel(// Providers ReadOnlyObjectProperty componentLibrary, - ReadOnlyObjectProperty voltageLevelLayoutFactoryCreator, + Property voltageLevelLayoutFactoryType, ReadOnlyObjectProperty substationLayoutFactory, ReadOnlyObjectProperty cgmesDLDiagramName, // Styles @@ -134,7 +129,12 @@ public SingleLineDiagramModel(// Providers // Providers this.currentComponentLibrary.bind(componentLibrary); - this.currentVoltageLevelLayoutFactoryCreator.bind(voltageLevelLayoutFactoryCreator); + this.voltageLevelLayoutFactoryBean = new VoltageLevelLayoutFactoryBean(voltageLevelLayoutFactoryType, + stackFeeders, + exceptionWhenPatternUnhandled, + handleShunts, + removeFictitiousNodes, + substituteSingularFictitiousNodes); this.currentSubstationLayoutFactory.bind(substationLayoutFactory); this.currentCgmesDLDiagramName.bind(cgmesDLDiagramName); @@ -182,10 +182,6 @@ 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()); @@ -193,14 +189,10 @@ public void initProviders() { // 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 @@ -212,12 +204,12 @@ public void updateFrom(Network network) { } // Set all providers list substationLayouts.setAll(nameToSubstationLayoutFactoryMap.values()); - voltageLevelLayouts.setAll(nameToVoltageLevelLayoutFactoryCreatorMap.values()); } public void addListener(ChangeListener changeListener) { layoutParametersBean.addListener(changeListener); svgParametersBean.addListener(changeListener); + voltageLevelLayoutFactoryBean.addListener(changeListener); } public LayoutParameters getLayoutParameters() { @@ -259,8 +251,8 @@ public StyleProvider getStyleProvider(Network network) { return new StyleProvidersList(styles); } - public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator() { - return currentVoltageLevelLayoutFactoryCreator.get(); + public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator(Network network) { + return voltageLevelLayoutFactoryBean.getVoltageLevelLayoutFactoryCreator(network); } public SubstationLayoutFactory getSubstationLayoutFactory() { @@ -271,10 +263,6 @@ public ObservableList getComponentLibraries() { return componentLibraries; } - public ObservableList getVoltageLevelLayouts() { - return voltageLevelLayouts; - } - public ObservableList getSubstationLayouts() { return substationLayouts; } @@ -312,17 +300,51 @@ public SubstationLayoutFactory fromString(String item) { }; } - public StringConverter getVoltageLevelLayoutFactoryCreatorStringConverter() { + public StringConverter getVoltageLevelLayoutFactoryCreatorStringConverter() { return new StringConverter<>() { @Override - public String toString(VoltageLevelLayoutFactoryCreator object) { - Optional label = nameToVoltageLevelLayoutFactoryCreatorMap.keySet().stream().filter(name -> nameToVoltageLevelLayoutFactoryCreatorMap.get(name) == object).findFirst(); - return label.orElse(UNKNOWN_ITEM); + public String toString(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType type) { + switch (type) { + case SMART -> { + return SMART_VOLTAGELEVEL_LAYOUT; + } + case AUTO_EXTENSIONS -> { + return AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT; + } + case AUTO_WITHOUT_EXTENSIONS_CLUSTERING -> { + return AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT; + } + case RANDOM -> { + return RANDOM_VOLTAGELEVEL_LAYOUT; + } + case CGMES -> { + return CGMES_VOLTAGELEVEL_LAYOUT; + } + default -> throw new UnsupportedOperationException("This code cannot be reach, missing case '" + type.name() + "'"); + } } @Override - public VoltageLevelLayoutFactoryCreator fromString(String item) { - return nameToVoltageLevelLayoutFactoryCreatorMap.get(item); + public VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType fromString(String item) { + + switch (item) { + case SMART_VOLTAGELEVEL_LAYOUT -> { + return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.SMART; + } + case AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT -> { + return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_EXTENSIONS; + } + case AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT -> { + return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_WITHOUT_EXTENSIONS_CLUSTERING; + } + case RANDOM_VOLTAGELEVEL_LAYOUT -> { + return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.RANDOM; + } + case CGMES_VOLTAGELEVEL_LAYOUT -> { + return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES; + } + default -> throw new UnsupportedOperationException("This code cannot be reach, missing case '" + item + "'"); + } } }; } diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramViewController.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramViewController.java index fcb249f..7599f5f 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramViewController.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SingleLineDiagramViewController.java @@ -11,11 +11,8 @@ import com.powsybl.diagram.viewer.common.AbstractDiagramViewController; import com.powsybl.iidm.network.Container; import com.powsybl.iidm.network.Network; -import com.powsybl.sld.cgmes.dl.iidm.extensions.NetworkDiagramData; -import com.powsybl.sld.cgmes.layout.CgmesVoltageLevelLayoutFactory; +import com.powsybl.sld.cgmes.dl.iidm.extensions.*; import com.powsybl.sld.layout.LayoutParameters; -import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactory; -import com.powsybl.sld.layout.VoltageLevelLayoutFactoryCreator; import com.powsybl.sld.layout.SubstationLayoutFactory; import com.powsybl.sld.library.ComponentLibrary; import javafx.beans.binding.Bindings; @@ -26,6 +23,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.control.*; +import javafx.scene.layout.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,7 +65,7 @@ public class SingleLineDiagramViewController extends AbstractDiagramViewControll public ComboBox substationLayoutComboBox; @FXML - public ComboBox voltageLevelLayoutComboBox; + public ChoiceBox voltageLevelLayoutComboBox; @FXML public ComboBox cgmesDLDiagramsComboBox; @@ -252,17 +250,16 @@ private void initialize() { substationLayoutComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getSubstationLayouts())); substationLayoutComboBox.setConverter(model.getSubstationLayoutStringConverter()); substationLayoutComboBox.getSelectionModel().selectFirst(); // Default selection without Network + // VoltageLevel layout - voltageLevelLayoutComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getVoltageLevelLayouts())); voltageLevelLayoutComboBox.setConverter(model.getVoltageLevelLayoutFactoryCreatorStringConverter()); - voltageLevelLayoutComboBox.getSelectionModel().selectFirst(); // Default selection without Network // CGMES-DL Diagrams cgmesDLDiagramsComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getCgmesDLDiagramNames())); cgmesDLDiagramsComboBox.getSelectionModel().selectFirst(); // Default selection without Network // PositionVoltageLevelLayoutFactory - BooleanBinding disableBinding = Bindings.createBooleanBinding(() -> voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() instanceof PositionVoltageLevelLayoutFactory, voltageLevelLayoutComboBox.getSelectionModel().selectedItemProperty()); + BooleanBinding disableBinding = Bindings.createBooleanBinding(() -> voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_EXTENSIONS || voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_WITHOUT_EXTENSIONS_CLUSTERING, voltageLevelLayoutComboBox.getSelectionModel().selectedItemProperty()); stackFeedersCheckBox.visibleProperty().bind(disableBinding); exceptionWhenPatternUnhandledCheckBox.visibleProperty().bind(disableBinding); handleShuntsCheckBox.visibleProperty().bind(disableBinding); @@ -279,7 +276,6 @@ private void initialize() { public void addListener(ChangeListener changeListener) { componentLibraryComboBox.valueProperty().addListener(changeListener); substationLayoutComboBox.valueProperty().addListener(changeListener); - voltageLevelLayoutComboBox.valueProperty().addListener(changeListener); cgmesDLDiagramsComboBox.valueProperty().addListener(changeListener); basicStyleProviderCheckBox.selectedProperty().addListener(changeListener); @@ -288,13 +284,6 @@ public void addListener(ChangeListener changeListener) { highlightStyleProviderCheckBox.selectedProperty().addListener(changeListener); topologicalStyleProviderCheckBox.selectedProperty().addListener(changeListener); - // PositionVoltageLevelLayoutFactory - stackFeedersCheckBox.selectedProperty().addListener(changeListener); - exceptionWhenPatternUnhandledCheckBox.selectedProperty().addListener(changeListener); - handleShuntsCheckBox.selectedProperty().addListener(changeListener); - removeFictitiousNodesCheckBox.selectedProperty().addListener(changeListener); - substituteSingularFictitiousNodesCheckBox.selectedProperty().addListener(changeListener); - // LayoutParameters model.addListener(changeListener); } @@ -345,7 +334,7 @@ public void updateFrom(final ObjectProperty networkProperty) { getModel().updateFrom(networkProperty.get()); cgmesDLDiagramsComboBox.disableProperty().unbind(); cgmesDLDiagramsComboBox.disableProperty().bind(Bindings.createBooleanBinding(() -> { - boolean cgmesSelected = voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() instanceof CgmesVoltageLevelLayoutFactory; + boolean cgmesSelected = voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES; return cgmesSelected && NetworkDiagramData.checkNetworkDiagramData(networkProperty.get()); }, voltageLevelLayoutComboBox.getSelectionModel().selectedItemProperty()).not()); @@ -360,11 +349,20 @@ public void updateFrom(final ObjectProperty networkProperty) { highlightStyleProviderCheckBox.disableProperty().bind(Bindings.createBooleanBinding(() -> networkProperty.get() != null, networkProperty).not()); topologicalStyleProviderCheckBox.disableProperty().unbind(); topologicalStyleProviderCheckBox.disableProperty().bind(Bindings.createBooleanBinding(() -> networkProperty.get() != null, networkProperty).not()); - + // Hide SMART & CGMES if no network available + if (networkProperty.get() == null) { + voltageLevelLayoutComboBox.getItems().remove(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.SMART); + voltageLevelLayoutComboBox.getItems().remove(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES); + } else { + if (!voltageLevelLayoutComboBox.getItems().contains(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.SMART)) { + voltageLevelLayoutComboBox.getItems().add(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.SMART.ordinal(), VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.SMART); + } + if (!voltageLevelLayoutComboBox.getItems().contains(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES)) { + voltageLevelLayoutComboBox.getItems().add(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES.ordinal(), VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES); + } + } // Horizontal selection substationLayoutComboBox.getSelectionModel().select(1); - // Smart selection - voltageLevelLayoutComboBox.getSelectionModel().selectLast(); // CGMES-DL Diagrams first selection cgmesDLDiagramsComboBox.getSelectionModel().selectFirst(); } diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/VoltageLevelLayoutFactoryBean.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/VoltageLevelLayoutFactoryBean.java new file mode 100644 index 0000000..1747736 --- /dev/null +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/VoltageLevelLayoutFactoryBean.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2023, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.diagram.viewer.sld; + +import com.powsybl.iidm.network.*; +import com.powsybl.sld.cgmes.layout.*; +import com.powsybl.sld.layout.*; +import com.powsybl.sld.layout.positionbyclustering.*; +import javafx.beans.property.*; +import javafx.beans.value.ChangeListener; + +import java.util.*; + +/** + * @author Thomas Adam + */ +public class VoltageLevelLayoutFactoryBean { + + public enum VoltageLevelLayoutFactoryType { + AUTO_EXTENSIONS, AUTO_WITHOUT_EXTENSIONS_CLUSTERING, CGMES, RANDOM, SMART + } + + private final ObjectProperty factoryType = new SimpleObjectProperty<>(); + + // PositionVoltageLevelLayoutFactory + private final EnumMap positionLayoutParametersByType = new EnumMap<>(VoltageLevelLayoutFactoryType.class); + + public VoltageLevelLayoutFactoryBean(Property type, + // PositionVoltageLevelLayoutFactory + BooleanProperty stackFeeders, + BooleanProperty exceptionWhenPatternUnhandled, + BooleanProperty handleShunts, + BooleanProperty removeFictitiousNodes, + BooleanProperty substituteSingularFictitiousNodes) { + // Current selection + this.factoryType.bindBidirectional(type); + + // Manage history for Position VoltageLevel layouts + this.positionLayoutParametersByType.put(VoltageLevelLayoutFactoryType.AUTO_EXTENSIONS, new PositionVoltageLevelLayoutBean()); + this.positionLayoutParametersByType.put(VoltageLevelLayoutFactoryType.AUTO_WITHOUT_EXTENSIONS_CLUSTERING, new PositionVoltageLevelLayoutBean()); + this.factoryType.addListener((observable, oldValue, newValue) -> { + PositionVoltageLevelLayoutBean oldParameters = positionLayoutParametersByType.get(oldValue); + if (oldParameters != null) { + stackFeeders.unbindBidirectional(oldParameters.stackFeedersProperty()); + exceptionWhenPatternUnhandled.unbindBidirectional(oldParameters.exceptionWhenPatternUnhandledProperty()); + handleShunts.unbindBidirectional(oldParameters.handleShuntsProperty()); + removeFictitiousNodes.unbindBidirectional(oldParameters.removeFictitiousNodesProperty()); + substituteSingularFictitiousNodes.unbindBidirectional(oldParameters.substituteSingularFictitiousNodesProperty()); + } + PositionVoltageLevelLayoutBean newParameters = positionLayoutParametersByType.get(newValue); + if (newParameters != null) { + stackFeeders.bindBidirectional(newParameters.stackFeedersProperty()); + exceptionWhenPatternUnhandled.bindBidirectional(newParameters.exceptionWhenPatternUnhandledProperty()); + handleShunts.bindBidirectional(newParameters.handleShuntsProperty()); + removeFictitiousNodes.bindBidirectional(newParameters.removeFictitiousNodesProperty()); + substituteSingularFictitiousNodes.bindBidirectional(newParameters.substituteSingularFictitiousNodesProperty()); + } + }); + } + + public void addListener(ChangeListener changeListener) { + // PositionVoltageLevelLayoutFactory + this.factoryType.addListener(changeListener); + this.positionLayoutParametersByType.forEach((k, v) -> v.addListener(changeListener)); + } + + public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator(Network network) { + VoltageLevelLayoutFactoryType type = factoryType.get(); + switch (type) { + case SMART -> { + return VoltageLevelLayoutFactoryCreator.newSmartVoltageLevelLayoutFactoryCreator(); + } + case AUTO_EXTENSIONS -> { + return VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator(new PositionByClustering(), positionLayoutParametersByType.get(type).getParameters()); + } + case AUTO_WITHOUT_EXTENSIONS_CLUSTERING -> { + return VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator(positionLayoutParametersByType.get(type).getParameters()); + } + case RANDOM -> { + return i -> new RandomVoltageLevelLayoutFactory(500.0, 500.0); + } + case CGMES -> { + return i -> new CgmesVoltageLevelLayoutFactory(network); + } + } + throw new UnsupportedOperationException("This code cannot be reach, missing case '" + type.name() + "'"); + } +} diff --git a/diagram-viewer/src/main/resources/sld/view.fxml b/diagram-viewer/src/main/resources/sld/view.fxml index 978e5df..198bea8 100644 --- a/diagram-viewer/src/main/resources/sld/view.fxml +++ b/diagram-viewer/src/main/resources/sld/view.fxml @@ -64,7 +64,7 @@