From 666db867d5881f2d883b4561c6c099d53ff13794 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Tue, 6 Feb 2024 14:35:58 +0100 Subject: [PATCH] Remove useless bean classes creation Signed-off-by: Thomas ADAM --- .../sld/PositionVoltageLevelLayoutBean.java | 67 ----------- .../sld/SingleLineDiagramController.java | 16 ++- .../viewer/sld/SingleLineDiagramModel.java | 98 +++------------- .../sld/SingleLineDiagramViewController.java | 84 ++++++-------- .../sld/VoltageLevelLayoutFactoryBean.java | 107 ------------------ .../src/main/resources/sld/view.fxml | 17 +-- 6 files changed, 63 insertions(+), 326 deletions(-) delete mode 100644 diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/PositionVoltageLevelLayoutBean.java delete 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 deleted file mode 100644 index c00d707..0000000 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/PositionVoltageLevelLayoutBean.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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()) - .setExceptionIfPatternNotHandled(exceptionWhenPatternUnhandled.get()) - .setHandleShunts(handleShunts.get()) - .setRemoveUnnecessaryFictitiousNodes(removeFictitiousNodes.get()) - .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 906aa85..78ef283 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 @@ -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; @@ -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 @@ -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); @@ -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 sldService = new Service<>() { @Override protected Task createTask() { @@ -90,7 +94,7 @@ protected ContainerResult call() { .setComponentLibrary(model.getComponentLibrary()) .setSubstationLayoutFactory(model.getSubstationLayoutFactory()) .setStyleProviderFactory(model::getStyleProvider) - .setVoltageLevelLayoutFactoryCreator(model.getVoltageLevelLayoutFactoryCreator(network)); + .setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator); 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 1406606..37f0d72 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 @@ -10,7 +10,7 @@ import com.powsybl.diagram.viewer.common.DiagramModel; import com.powsybl.iidm.network.Network; import com.powsybl.sld.cgmes.dl.iidm.extensions.*; -import com.powsybl.sld.cgmes.layout.CgmesSubstationLayoutFactory; +import com.powsybl.sld.cgmes.layout.*; import com.powsybl.sld.layout.*; import com.powsybl.sld.library.ComponentLibrary; @@ -30,6 +30,21 @@ */ public class SingleLineDiagramModel extends DiagramModel { + public enum VoltageLevelLayoutFactoryType { + AUTO_EXTENSIONS, AUTO_WITHOUT_EXTENSIONS_CLUSTERING, CGMES, RANDOM, SMART; + + @Override + public String toString() { + return switch (this) { + case SMART -> "Smart"; + case AUTO_EXTENSIONS -> "Auto extensions"; + case AUTO_WITHOUT_EXTENSIONS_CLUSTERING -> "Auto without extensions Clustering"; + case RANDOM -> "Random"; + case CGMES -> "CGMES"; + }; + } + } + private static final String UNKNOWN_ITEM = "???"; // LayoutParameters @@ -51,15 +66,6 @@ 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 VoltageLevelLayoutFactoryBean voltageLevelLayoutFactoryBean; - // Substation layout provider private static final String HORIZONTAL_SUBSTATION_LAYOUT = "Horizontal"; private static final String VERTICAL_SUBSTATION_LAYOUT = "Vertical"; @@ -74,7 +80,6 @@ public class SingleLineDiagramModel extends DiagramModel { public SingleLineDiagramModel(// Providers ReadOnlyObjectProperty componentLibrary, - Property voltageLevelLayoutFactoryType, ReadOnlyObjectProperty substationLayoutFactory, ReadOnlyObjectProperty cgmesDLDiagramName, // Styles @@ -85,15 +90,6 @@ public SingleLineDiagramModel(// Providers Property animationThreshold2, BooleanProperty highlightStyleProvider, BooleanProperty topologicalStyleProvider, - // PositionVoltageLevelLayoutFactory - BooleanProperty stackFeeders, - BooleanProperty exceptionWhenPatternUnhandled, - BooleanProperty handleShunts, - BooleanProperty removeFictitiousNodes, - BooleanProperty substituteSingularFictitiousNodes, - // RandomVoltageLevelLayoutFactory - Property width, - Property height, // LayoutParameters Property diagramPaddingTopBottom, Property diagramPaddingLeftRight, @@ -132,14 +128,6 @@ public SingleLineDiagramModel(// Providers // Providers this.currentComponentLibrary.bind(componentLibrary); - this.voltageLevelLayoutFactoryBean = new VoltageLevelLayoutFactoryBean(voltageLevelLayoutFactoryType, - stackFeeders, - exceptionWhenPatternUnhandled, - handleShunts, - removeFictitiousNodes, - substituteSingularFictitiousNodes, - width, - height); this.currentSubstationLayoutFactory.bind(substationLayoutFactory); this.currentCgmesDLDiagramName.bind(cgmesDLDiagramName); @@ -215,7 +203,6 @@ public void updateFrom(Network network) { public void addListener(ChangeListener changeListener) { layoutParametersBean.addListener(changeListener); svgParametersBean.addListener(changeListener); - voltageLevelLayoutFactoryBean.addListener(changeListener); } public LayoutParameters getLayoutParameters() { @@ -257,10 +244,6 @@ public StyleProvider getStyleProvider(Network network) { return new StyleProvidersList(styles); } - public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator(Network network) { - return voltageLevelLayoutFactoryBean.getVoltageLevelLayoutFactoryCreator(network); - } - public SubstationLayoutFactory getSubstationLayoutFactory() { return currentSubstationLayoutFactory.get(); } @@ -305,53 +288,4 @@ public SubstationLayoutFactory fromString(String item) { } }; } - - public StringConverter getVoltageLevelLayoutFactoryCreatorStringConverter() { - return new StringConverter<>() { - @Override - 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 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 85ce449..f415647 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 @@ -12,8 +12,9 @@ import com.powsybl.iidm.network.Container; import com.powsybl.iidm.network.Network; import com.powsybl.sld.cgmes.dl.iidm.extensions.*; -import com.powsybl.sld.layout.LayoutParameters; -import com.powsybl.sld.layout.SubstationLayoutFactory; +import com.powsybl.sld.cgmes.layout.*; +import com.powsybl.sld.layout.*; +import com.powsybl.sld.layout.positionbyclustering.*; import com.powsybl.sld.library.ComponentLibrary; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; @@ -68,7 +69,7 @@ public class SingleLineDiagramViewController extends AbstractDiagramViewControll public ComboBox substationLayoutComboBox; @FXML - public ChoiceBox voltageLevelLayoutComboBox; + public ChoiceBox voltageLevelLayoutComboBox; @FXML public ComboBox cgmesDLDiagramsComboBox; @@ -131,15 +132,6 @@ public class SingleLineDiagramViewController extends AbstractDiagramViewControll @FXML public CheckBox substituteSingularFictitiousNodesCheckBox; - @FXML - public HBox randomHBox; - - @FXML - public Spinner randomWidthSpinner; - - @FXML - public Spinner randomHeightSpinner; - @FXML public Spinner scaleFactorSpinner; @@ -198,7 +190,6 @@ private void initialize() { model = new SingleLineDiagramModel( // Providers componentLibraryComboBox.valueProperty(), - voltageLevelLayoutComboBox.valueProperty(), substationLayoutComboBox.valueProperty(), cgmesDLDiagramsComboBox.valueProperty(), // - Styles @@ -209,15 +200,6 @@ private void initialize() { animationThreshold2Spinner.getValueFactory().valueProperty(), highlightStyleProviderCheckBox.selectedProperty(), topologicalStyleProviderCheckBox.selectedProperty(), - // PositionVoltageLevelLayoutFactory - stackFeedersCheckBox.selectedProperty(), - exceptionWhenPatternUnhandledCheckBox.selectedProperty(), - handleShuntsCheckBox.selectedProperty(), - removeFictitiousNodesCheckBox.selectedProperty(), - substituteSingularFictitiousNodesCheckBox.selectedProperty(), - // RandomVoltageLevelLayoutFactory - randomWidthSpinner.getValueFactory().valueProperty(), - randomHeightSpinner.getValueFactory().valueProperty(), // LayoutParameters diagramPaddingTopBottomSpinner.getValueFactory().valueProperty(), diagramPaddingLeftRightSpinner.getValueFactory().valueProperty(), @@ -266,20 +248,12 @@ private void initialize() { substationLayoutComboBox.setConverter(model.getSubstationLayoutStringConverter()); substationLayoutComboBox.getSelectionModel().selectFirst(); // Default selection without Network - // VoltageLevel layout - voltageLevelLayoutComboBox.setConverter(model.getVoltageLevelLayoutFactoryCreatorStringConverter()); - // CGMES-DL Diagrams cgmesDLDiagramsComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getCgmesDLDiagramNames())); cgmesDLDiagramsComboBox.getSelectionModel().selectFirst(); // Default selection without Network - // RandomVoltageLevelLayoutFactory - BooleanBinding randomSelectionBinding = Bindings.createBooleanBinding(() -> voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.RANDOM, voltageLevelLayoutComboBox.getSelectionModel().selectedItemProperty()); - randomHBox.visibleProperty().bind(randomSelectionBinding); - randomHBox.managedProperty().bind(randomHBox.visibleProperty()); - // PositionVoltageLevelLayoutFactory - BooleanBinding disableBinding = Bindings.createBooleanBinding(() -> voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_EXTENSIONS || voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_WITHOUT_EXTENSIONS_CLUSTERING, voltageLevelLayoutComboBox.getSelectionModel().selectedItemProperty()); + BooleanBinding disableBinding = Bindings.createBooleanBinding(() -> voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == SingleLineDiagramModel.VoltageLevelLayoutFactoryType.AUTO_EXTENSIONS || voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == SingleLineDiagramModel.VoltageLevelLayoutFactoryType.AUTO_WITHOUT_EXTENSIONS_CLUSTERING, voltageLevelLayoutComboBox.getSelectionModel().selectedItemProperty()); stackFeedersCheckBox.visibleProperty().bind(disableBinding); exceptionWhenPatternUnhandledCheckBox.visibleProperty().bind(disableBinding); handleShuntsCheckBox.visibleProperty().bind(disableBinding); @@ -304,19 +278,27 @@ public void addListener(ChangeListener changeListener) { highlightStyleProviderCheckBox.selectedProperty().addListener(changeListener); topologicalStyleProviderCheckBox.selectedProperty().addListener(changeListener); + voltageLevelLayoutComboBox.valueProperty().addListener(changeListener); + stackFeedersCheckBox.selectedProperty().addListener(changeListener); + exceptionWhenPatternUnhandledCheckBox.selectedProperty().addListener(changeListener); + handleShuntsCheckBox.selectedProperty().addListener(changeListener); + removeFictitiousNodesCheckBox.selectedProperty().addListener(changeListener); + substituteSingularFictitiousNodesCheckBox.selectedProperty().addListener(changeListener); + // LayoutParameters model.addListener(changeListener); } public void updateAllDiagrams(Network network, Container selectedContainer) { if (selectedContainer != null) { - SingleLineDiagramController.updateDiagram(network, model, model.getSelectedContainerResult(), selectedContainer); + SingleLineDiagramController.updateDiagram(network, model, model.getSelectedContainerResult(), selectedContainer, + getVoltageLevelLayoutFactoryCreator()); } - model.getCheckedContainerStream().forEach(container -> SingleLineDiagramController.updateDiagram(network, model, model.getCheckedContainerResult(container), container)); + model.getCheckedContainerStream().forEach(container -> SingleLineDiagramController.updateDiagram(network, model, model.getCheckedContainerResult(container), container, getVoltageLevelLayoutFactoryCreator())); } public void createDiagram(SingleLineDiagramJsHandler jsHandler, Network network, Container container) { - selectedDiagramController.createDiagram(jsHandler, network, model, model.getSelectedContainerResult(), container); + selectedDiagramController.createDiagram(jsHandler, network, model, model.getSelectedContainerResult(), container, getVoltageLevelLayoutFactoryCreator()); } public void createCheckedTab(SingleLineDiagramJsHandler jsHandler, @@ -332,7 +314,8 @@ public void createCheckedTab(SingleLineDiagramJsHandler jsHandler, network, model, model.getCheckedContainerResult(container), - container); + container, + getVoltageLevelLayoutFactoryCreator()); super.createCheckedTab(containerTreeItem, tabName, diagram, checkedDiagramController); } catch (IOException e) { LOGGER.error(e.toString(), e); @@ -354,7 +337,7 @@ public void updateFrom(final ObjectProperty networkProperty) { getModel().updateFrom(networkProperty.get()); cgmesDLDiagramsComboBox.disableProperty().unbind(); cgmesDLDiagramsComboBox.disableProperty().bind(Bindings.createBooleanBinding(() -> { - boolean cgmesSelected = voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES; + boolean cgmesSelected = voltageLevelLayoutComboBox.getSelectionModel().getSelectedItem() == SingleLineDiagramModel.VoltageLevelLayoutFactoryType.CGMES; return cgmesSelected && NetworkDiagramData.checkNetworkDiagramData(networkProperty.get()); }, voltageLevelLayoutComboBox.getSelectionModel().selectedItemProperty()).not()); @@ -369,18 +352,6 @@ 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); // CGMES-DL Diagrams first selection @@ -396,4 +367,21 @@ protected AbstractDiagramController getSelectedDiagramController() { protected AbstractDiagramController getCheckedDiagramController(Tab tabInChecked) { return checkedDiagramControllers.get(tabInChecked); } + + public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator() { + PositionVoltageLevelLayoutFactoryParameters parameters = new PositionVoltageLevelLayoutFactoryParameters(); + parameters.setFeederStacked(stackFeedersCheckBox.isSelected()) + .setExceptionIfPatternNotHandled(exceptionWhenPatternUnhandledCheckBox.isSelected()) + .setHandleShunts(handleShuntsCheckBox.isSelected()) + .setRemoveUnnecessaryFictitiousNodes(removeFictitiousNodesCheckBox.isSelected()) + .setSubstituteSingularFictitiousByFeederNode(substituteSingularFictitiousNodesCheckBox.isSelected()); + SingleLineDiagramModel.VoltageLevelLayoutFactoryType type = voltageLevelLayoutComboBox.getValue(); + return switch (type) { + case SMART -> SmartVoltageLevelLayoutFactory::new; + case AUTO_EXTENSIONS -> network -> new PositionVoltageLevelLayoutFactory(new PositionByClustering(), parameters); + case AUTO_WITHOUT_EXTENSIONS_CLUSTERING -> network -> new PositionVoltageLevelLayoutFactory(parameters); + case RANDOM -> network -> new RandomVoltageLevelLayoutFactory(500.0, 500.0); + case CGMES -> CgmesVoltageLevelLayoutFactory::new; + }; + } } 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 deleted file mode 100644 index b3fd904..0000000 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/VoltageLevelLayoutFactoryBean.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * 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); - - // RandomVoltageLevelLayoutFactory - private final ObjectProperty width = new SimpleObjectProperty<>(500.0); - private final ObjectProperty height = new SimpleObjectProperty<>(500.0); - - public VoltageLevelLayoutFactoryBean(Property type, - // PositionVoltageLevelLayoutFactory - BooleanProperty stackFeeders, - BooleanProperty exceptionWhenPatternUnhandled, - BooleanProperty handleShunts, - BooleanProperty removeFictitiousNodes, - BooleanProperty substituteSingularFictitiousNodes, - // RandomVoltageLevelLayoutFactory - Property width, - Property height) { - // 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()); - } - }); - - // RandomVoltageLevelLayoutFactory - width.bindBidirectional(this.width); // Keep this binding order in order to initialize with Bean value - height.bindBidirectional(this.height); // Keep this binding order in order to initialize with Bean value - } - - public void addListener(ChangeListener changeListener) { - // PositionVoltageLevelLayoutFactory - this.factoryType.addListener(changeListener); - this.positionLayoutParametersByType.forEach((k, v) -> v.addListener(changeListener)); - // RandomVoltageLevelLayoutFactory - this.width.addListener(changeListener); - this.height.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(this.width.get(), this.height.get()); - } - 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 48a4efc..b752136 100644 --- a/diagram-viewer/src/main/resources/sld/view.fxml +++ b/diagram-viewer/src/main/resources/sld/view.fxml @@ -65,26 +65,11 @@