diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2c46c84..99f5e5f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,11 +16,11 @@ jobs: - name: Checkout sources uses: actions/checkout@v2.3.4 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: Build diagram viewer with Maven run: mvn --file diagram-viewer --batch-mode -P jacoco,checks package diff --git a/diagram-viewer/pom.xml b/diagram-viewer/pom.xml index 2be067f..b6889fe 100644 --- a/diagram-viewer/pom.xml +++ b/diagram-viewer/pom.xml @@ -15,7 +15,7 @@ com.powsybl powsybl-parent - 4 + 15 @@ -35,7 +35,7 @@ UTF-8 - 11 + 17 19.0.2.1 0.0.8 2.0.7 @@ -43,7 +43,7 @@ 4.13.1 17 17 - 2023.2.0 + 2023.3.0 diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/Model.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/Model.java index 6297369..642d5e9 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/Model.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/Model.java @@ -28,7 +28,7 @@ public Model(BooleanProperty showNames, NetworkAreaDiagramModel nadModel, Single this.nadModel = nadModel; this.sldModel = sldModel; this.nadModel.getSvgParametersBean().bind(showNames); - this.sldModel.getLayoutParametersBean().bind(showNames); + this.sldModel.getSvgParametersBean().bind(showNames); } public void setNetwork(Network network) { diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramController.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramController.java index 1792f54..78f5481 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramController.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramController.java @@ -14,7 +14,9 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.Substation; import com.powsybl.iidm.network.VoltageLevel; +import com.powsybl.nad.NadParameters; import com.powsybl.nad.NetworkAreaDiagram; +import com.powsybl.nad.build.iidm.VoltageLevelFilter; import javafx.concurrent.Service; import javafx.concurrent.Task; import javafx.fxml.FXML; @@ -24,6 +26,7 @@ import java.io.IOException; import java.io.StringWriter; import java.util.List; +import java.util.function.Predicate; import java.util.stream.Collectors; /** @@ -54,13 +57,11 @@ protected Task createTask() { return new Task<>() { @Override protected String call() { - NetworkAreaDiagram nad = getNetworkAreaDiagram(network, model, container); - nad.draw(writer, - model.getSvgParameters(), - model.getLayoutParameters(), - model.getStyleProvider(network), - model.getLabelProvider(network), - model.getLayoutFactory()); + Predicate vls = getVoltageLevelFilter(network, model, container); + NadParameters nadParameters = new NadParameters(); + nadParameters.setLayoutParameters(model.getLayoutParameters()); + nadParameters.setSvgParameters(model.getSvgParameters()); + NetworkAreaDiagram.draw(network, writer, nadParameters, vls); return writer.toString(); } }; @@ -75,15 +76,15 @@ protected String call() { nadService.start(); } - private static NetworkAreaDiagram getNetworkAreaDiagram(Network network, NetworkAreaDiagramModel model, Container container) { + private static Predicate getVoltageLevelFilter(Network network, NetworkAreaDiagramModel model, Container container) { switch (container.getContainerType()) { case NETWORK: - return new NetworkAreaDiagram((Network) container); + return VoltageLevelFilter.NO_FILTER; case SUBSTATION: List vls = ((Substation) container).getVoltageLevelStream().map(VoltageLevel::getId).collect(Collectors.toList()); - return new NetworkAreaDiagram(network, vls, model.getDepth()); + return VoltageLevelFilter.createVoltageLevelsDepthFilter(network, vls, model.getDepth()); case VOLTAGE_LEVEL: - return new NetworkAreaDiagram(network, container.getId(), model.getDepth()); + return VoltageLevelFilter.createVoltageLevelDepthFilter(network, container.getId(), model.getDepth()); default: throw new AssertionError(); } diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramModel.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramModel.java index 2046e79..152294f 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramModel.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/NetworkAreaDiagramModel.java @@ -30,7 +30,7 @@ public class NetworkAreaDiagramModel extends DiagramModel { private static final String TOPOLOGICAL_STYLE_PROVIDER = "Topological"; // Layout Parameters - private final LayoutParametersBean layoutParameters; + private final LayoutParametersBean layoutParametersBean; // SVG Parameters private final SvgParametersBean svgParameters; @@ -67,7 +67,7 @@ public NetworkAreaDiagramModel(ReadOnlyObjectProperty depth, this.layoutFactory.bind(layout); // Layout parameters - layoutParameters = new LayoutParametersBean(textNodesIncluded, springRepulsionFactor); + layoutParametersBean = new LayoutParametersBean(textNodesIncluded, springRepulsionFactor); // SVG parameters svgParameters = new SvgParametersBean(infoAlongEdge, @@ -91,7 +91,7 @@ public SvgParameters getSvgParameters() { } public LayoutParameters getLayoutParameters() { - return layoutParameters.getLayoutParameters(); + return layoutParametersBean.getLayoutParameters(); } public LabelProvider getLabelProvider(Network network) { @@ -114,6 +114,6 @@ public SvgParametersBean getSvgParametersBean() { public void addListener(ChangeListener changeListener) { svgParameters.addListener(changeListener); - layoutParameters.addListener(changeListener); + layoutParametersBean.addListener(changeListener); } } diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/SvgParametersBean.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/SvgParametersBean.java index 2c47879..15e3dfa 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/SvgParametersBean.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/nad/SvgParametersBean.java @@ -53,6 +53,7 @@ public SvgParametersBean(// SVG parameters // Initialize SvgParameters defaultParameters = new SvgParameters(); + idDisplayed.setValue(defaultParameters.isIdDisplayed()); edgeInfoAlongEdge.setValue(defaultParameters.isEdgeInfoAlongEdge()); edgeNameDisplayed.setValue(defaultParameters.isEdgeNameDisplayed()); insertNameDesc.setValue(defaultParameters.isInsertNameDesc()); diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/LayoutParametersBean.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/LayoutParametersBean.java index a84527a..50b1202 100644 --- a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/LayoutParametersBean.java +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/LayoutParametersBean.java @@ -19,93 +19,41 @@ */ public class LayoutParametersBean { - private final BooleanProperty useName = new SimpleBooleanProperty(); - - // Layout Parameters private final ObjectProperty diagramPaddingTopBottom = new SimpleObjectProperty<>(); - private final ObjectProperty diagramPaddingLeftRight = new SimpleObjectProperty<>(); - private final ObjectProperty voltagePaddingTopBottom = new SimpleObjectProperty<>(); - private final ObjectProperty voltagePaddingLeftRight = new SimpleObjectProperty<>(); - private final ObjectProperty busbarVerticalSpace = new SimpleObjectProperty<>(); - private final ObjectProperty busbarHorizontalSpace = new SimpleObjectProperty<>(); - private final ObjectProperty cellWidth = new SimpleObjectProperty<>(); - private final ObjectProperty externCellHeight = new SimpleObjectProperty<>(); - private final ObjectProperty internCellHeight = new SimpleObjectProperty<>(); - private final ObjectProperty stackHeight = new SimpleObjectProperty<>(); - - private final BooleanProperty showGrid = new SimpleBooleanProperty(); - - private final BooleanProperty showInternalNodes = new SimpleBooleanProperty(); - - private final BooleanProperty drawStraightWires = new SimpleBooleanProperty(); - private final BooleanProperty disconnectorsOnBus = new SimpleBooleanProperty(); - private final ObjectProperty scaleFactor = new SimpleObjectProperty<>(); - - private final BooleanProperty avoidSVGComponentsDuplication = new SimpleBooleanProperty(); - private final BooleanProperty adaptCellHeightToContent = new SimpleBooleanProperty(); - private final ObjectPropertyminSpaceBetweenComponents = new SimpleObjectProperty<>(); - private final ObjectPropertyminimumExternCellHeight = new SimpleObjectProperty<>(); - private final ObjectProperty busBarAlignment = new SimpleObjectProperty<>(); - - private final BooleanProperty centerLabel = new SimpleBooleanProperty(); - - private final BooleanProperty labelDiagonal = new SimpleBooleanProperty(); - - private final ObjectPropertyangleLabel = new SimpleObjectProperty<>(); - - private final BooleanProperty addNodesInfos = new SimpleBooleanProperty(); - - private final BooleanProperty feederInfoSymmetry = new SimpleBooleanProperty(); - private final ObjectPropertyspaceForFeederInfos = new SimpleObjectProperty<>(); - private final ObjectPropertyfeederInfosOuterMargin = new SimpleObjectProperty<>(); - - private final ObjectPropertyfeederInfosIntraMargin = new SimpleObjectProperty<>(); - public LayoutParametersBean(Property diagramPaddingTopBottom, - Property diagramPaddingLeftRight, - Property voltagePaddingTopBottom, - Property voltagePaddingLeftRight, - Property busbarVerticalSpace, - Property busbarHorizontalSpace, - Property cellWidth, - Property externCellHeight, - Property internCellHeight, - Property stackHeight, - BooleanProperty showGrid, - BooleanProperty showInternalNodes, - BooleanProperty drawStraightWires, - BooleanProperty disconnectorsOnBus, - Property scaleFactor, - BooleanProperty avoidSVGComponentsDuplication, - BooleanProperty adaptCellHeightToContent, - Property minSpaceBetweenComponents, - Property minimumExternCellHeight, - Property busBarAlignment, - BooleanProperty centerLabel, - BooleanProperty labelDiagonal, - Property angleLabel, - BooleanProperty addNodesInfos, - BooleanProperty feederInfoSymmetry, - Property spaceForFeederInfos, - Property feederInfosOuterMargin, - Property feederInfosIntraMargin) { + Property diagramPaddingLeftRight, + Property voltagePaddingTopBottom, + Property voltagePaddingLeftRight, + Property busbarVerticalSpace, + Property busbarHorizontalSpace, + Property cellWidth, + Property externCellHeight, + Property internCellHeight, + Property stackHeight, + BooleanProperty disconnectorsOnBus, + Property scaleFactor, + BooleanProperty adaptCellHeightToContent, + Property minSpaceBetweenComponents, + Property minimumExternCellHeight, + Property busBarAlignment, + Property spaceForFeederInfos) { // bind this.diagramPaddingTopBottom.bindBidirectional(diagramPaddingTopBottom); this.diagramPaddingTopBottom.bindBidirectional(diagramPaddingTopBottom); @@ -118,65 +66,38 @@ public LayoutParametersBean(Property diagramPaddingTopBottom, this.externCellHeight.bindBidirectional(externCellHeight); this.internCellHeight.bindBidirectional(internCellHeight); this.stackHeight.bindBidirectional(stackHeight); - this.showGrid.bindBidirectional(showGrid); - this.showInternalNodes.bindBidirectional(showInternalNodes); - this.drawStraightWires.bindBidirectional(drawStraightWires); this.disconnectorsOnBus.bindBidirectional(disconnectorsOnBus); this.scaleFactor.bindBidirectional(scaleFactor); - this.avoidSVGComponentsDuplication.bindBidirectional(avoidSVGComponentsDuplication); this.adaptCellHeightToContent.bindBidirectional(adaptCellHeightToContent); this.minSpaceBetweenComponents.bindBidirectional(minSpaceBetweenComponents); this.minimumExternCellHeight.bindBidirectional(minimumExternCellHeight); this.busBarAlignment.bindBidirectional(busBarAlignment); - this.centerLabel.bindBidirectional(centerLabel); - this.labelDiagonal.bindBidirectional(labelDiagonal); - this.angleLabel.bindBidirectional(angleLabel); - this.addNodesInfos.bindBidirectional(addNodesInfos); - this.feederInfoSymmetry.bindBidirectional(feederInfoSymmetry); this.spaceForFeederInfos.bindBidirectional(spaceForFeederInfos); - this.feederInfosOuterMargin.bindBidirectional(feederInfosOuterMargin); - this.feederInfosIntraMargin.bindBidirectional(feederInfosIntraMargin); // Initialize - LayoutParameters defaultParameters = new LayoutParameters() - .setShowGrid(true) + LayoutParameters defaultLayoutParameters = new LayoutParameters() .setAdaptCellHeightToContent(true); - diagramPaddingTopBottom.setValue(defaultParameters.getDiagramPadding().getTop()); - diagramPaddingLeftRight.setValue(defaultParameters.getDiagramPadding().getLeft()); - voltagePaddingTopBottom.setValue(defaultParameters.getVoltageLevelPadding().getTop()); - voltagePaddingLeftRight.setValue(defaultParameters.getVoltageLevelPadding().getLeft()); - busbarVerticalSpace.setValue(defaultParameters.getVerticalSpaceBus()); - busbarHorizontalSpace.setValue(defaultParameters.getHorizontalBusPadding()); - cellWidth.setValue(defaultParameters.getCellWidth()); - externCellHeight.setValue(defaultParameters.getExternCellHeight()); - internCellHeight.setValue(defaultParameters.getInternCellHeight()); - stackHeight.setValue(defaultParameters.getStackHeight()); - showGrid.setValue(defaultParameters.isShowGrid()); - showInternalNodes.setValue(defaultParameters.isShowInternalNodes()); - drawStraightWires.setValue(defaultParameters.isDrawStraightWires()); - disconnectorsOnBus.setValue(defaultParameters.getComponentsOnBusbars().equals(List.of(ComponentTypeName.DISCONNECTOR))); - scaleFactor.setValue(defaultParameters.getScaleFactor()); - avoidSVGComponentsDuplication.setValue(defaultParameters.isAvoidSVGComponentsDuplication()); - adaptCellHeightToContent.setValue(defaultParameters.isAdaptCellHeightToContent()); - minSpaceBetweenComponents.setValue(defaultParameters.getMinSpaceBetweenComponents()); - minimumExternCellHeight.setValue(defaultParameters.getMinExternCellHeight()); - busBarAlignment.setValue(defaultParameters.getBusbarsAlignment()); - centerLabel.setValue(defaultParameters.isLabelCentered()); - labelDiagonal.setValue(defaultParameters.isLabelDiagonal()); - angleLabel.setValue(defaultParameters.getAngleLabelShift()); - addNodesInfos.setValue(defaultParameters.isAddNodesInfos()); - feederInfoSymmetry.setValue(defaultParameters.isFeederInfoSymmetry()); - spaceForFeederInfos.setValue(defaultParameters.getSpaceForFeederInfos()); - feederInfosOuterMargin.setValue(defaultParameters.getFeederInfosOuterMargin()); - feederInfosIntraMargin.setValue(defaultParameters.getFeederInfosIntraMargin()); - } - public void bind(BooleanProperty useName) { - this.useName.bind(useName); + diagramPaddingTopBottom.setValue(defaultLayoutParameters.getDiagramPadding().getTop()); + diagramPaddingLeftRight.setValue(defaultLayoutParameters.getDiagramPadding().getLeft()); + voltagePaddingTopBottom.setValue(defaultLayoutParameters.getVoltageLevelPadding().getTop()); + voltagePaddingLeftRight.setValue(defaultLayoutParameters.getVoltageLevelPadding().getLeft()); + busbarVerticalSpace.setValue(defaultLayoutParameters.getVerticalSpaceBus()); + busbarHorizontalSpace.setValue(defaultLayoutParameters.getHorizontalBusPadding()); + cellWidth.setValue(defaultLayoutParameters.getCellWidth()); + externCellHeight.setValue(defaultLayoutParameters.getExternCellHeight()); + internCellHeight.setValue(defaultLayoutParameters.getInternCellHeight()); + stackHeight.setValue(defaultLayoutParameters.getStackHeight()); + disconnectorsOnBus.setValue(defaultLayoutParameters.getComponentsOnBusbars().equals(List.of(ComponentTypeName.DISCONNECTOR))); + adaptCellHeightToContent.setValue(defaultLayoutParameters.isAdaptCellHeightToContent()); + minSpaceBetweenComponents.setValue(defaultLayoutParameters.getMinSpaceBetweenComponents()); + minimumExternCellHeight.setValue(defaultLayoutParameters.getMinExternCellHeight()); + busBarAlignment.setValue(defaultLayoutParameters.getBusbarsAlignment()); + spaceForFeederInfos.setValue(defaultLayoutParameters.getSpaceForFeederInfos()); + scaleFactor.setValue(defaultLayoutParameters.getCgmesScaleFactor()); } public void addListener(ChangeListener changeListener) { - this.useName.addListener(changeListener); this.diagramPaddingTopBottom.addListener(changeListener); this.diagramPaddingTopBottom.addListener(changeListener); this.diagramPaddingLeftRight.addListener(changeListener); @@ -188,27 +109,16 @@ public void addListener(ChangeListener changeListener) { this.externCellHeight.addListener(changeListener); this.internCellHeight.addListener(changeListener); this.stackHeight.addListener(changeListener); - this.showGrid.addListener(changeListener); - this.showInternalNodes.addListener(changeListener); - this.drawStraightWires.addListener(changeListener); this.disconnectorsOnBus.addListener(changeListener); this.scaleFactor.addListener(changeListener); - this.avoidSVGComponentsDuplication.addListener(changeListener); this.adaptCellHeightToContent.addListener(changeListener); this.minSpaceBetweenComponents.addListener(changeListener); this.minimumExternCellHeight.addListener(changeListener); this.busBarAlignment.addListener(changeListener); - this.centerLabel.addListener(changeListener); - this.labelDiagonal.addListener(changeListener); - this.angleLabel.addListener(changeListener); - this.addNodesInfos.addListener(changeListener); - this.feederInfoSymmetry.addListener(changeListener); this.spaceForFeederInfos.addListener(changeListener); - this.feederInfosOuterMargin.addListener(changeListener); - this.feederInfosIntraMargin.addListener(changeListener); } - public LayoutParameters getLayoutParameters(String diagramName) { + public LayoutParameters getLayoutParameters() { return new LayoutParameters() .setDiagrammPadding(diagramPaddingLeftRight.get(), diagramPaddingTopBottom.get(), @@ -218,34 +128,18 @@ public LayoutParameters getLayoutParameters(String diagramName) { voltagePaddingTopBottom.get(), voltagePaddingLeftRight.get(), voltagePaddingTopBottom.get()) - .setUseName(useName.get()) - .setDiagramName(diagramName) .setVerticalSpaceBus(busbarVerticalSpace.get()) .setHorizontalBusPadding(busbarHorizontalSpace.get()) .setCellWidth(cellWidth.get()) .setExternCellHeight(externCellHeight.get()) .setInternCellHeight(internCellHeight.get()) .setStackHeight(stackHeight.get()) - .setShowGrid(showGrid.get()) - .setShowInternalNodes(showInternalNodes.get()) - .setDrawStraightWires(drawStraightWires.get()) .setComponentsOnBusbars(disconnectorsOnBus.get() ? List.of(ComponentTypeName.DISCONNECTOR) : Collections.emptyList()) - .setScaleFactor(scaleFactor.get()) - .setAvoidSVGComponentsDuplication(avoidSVGComponentsDuplication.get()) + .setCgmesScaleFactor(scaleFactor.get()) .setAdaptCellHeightToContent(adaptCellHeightToContent.get()) .setMinSpaceBetweenComponents(minSpaceBetweenComponents.get()) .setMinExternCellHeight(minimumExternCellHeight.get()) .setBusbarsAlignment(busBarAlignment.get()) - .setLabelCentered(centerLabel.get()) - .setLabelDiagonal(labelDiagonal.get()) - .setAngleLabelShift(angleLabel.get()) - .setAddNodesInfos(addNodesInfos.get()) - .setFeederInfoSymmetry(feederInfoSymmetry.get()) - .setSpaceForFeederInfos(spaceForFeederInfos.get()) - .setFeederInfosOuterMargin(feederInfosOuterMargin.get()) - .setFeederInfosIntraMargin(feederInfosIntraMargin.get()) - // Forced values - .setCssLocation(LayoutParameters.CssLocation.INSERTED_IN_SVG) - .setSvgWidthAndHeightAdded(true); + .setSpaceForFeederInfos(spaceForFeederInfos.get()); } } 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 982421b..f57eebc 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 @@ -11,9 +11,7 @@ import com.powsybl.diagram.viewer.common.ContainerResult; import com.powsybl.iidm.network.*; import com.powsybl.sld.SingleLineDiagram; -import com.powsybl.sld.layout.LayoutParameters; -import com.powsybl.sld.svg.DefaultDiagramLabelProvider; -import com.powsybl.sld.svg.DiagramLabelProvider; +import com.powsybl.sld.SldParameters; import com.powsybl.sld.svg.styles.StyleProvider; import javafx.beans.property.StringProperty; import javafx.concurrent.Service; @@ -86,22 +84,18 @@ protected ContainerResult call() { StringWriter metadataWriter = new StringWriter(); StringWriter jsonWriter = new StringWriter()) { - LayoutParameters diagramLayoutParameters = model.getLayoutParameters(); - - DiagramLabelProvider initProvider = new DefaultDiagramLabelProvider(network, - model.getComponentLibrary(), - diagramLayoutParameters); + SldParameters sldParameters = new SldParameters() + .setLayoutParameters(model.getLayoutParameters()) + .setSvgParameters(model.getSvgParameters()) + .setComponentLibrary(model.getComponentLibrary()) + .setSubstationLayoutFactory(model.getSubstationLayoutFactory()) + .setStyleProviderFactory(model::getStyleProvider) + .setVoltageLevelLayoutFactoryCreator(model.getVoltageLevelLayoutFactoryCreator()); SingleLineDiagram.draw(network, container.getId(), svgWriter, metadataWriter, - diagramLayoutParameters, - model.getComponentLibrary(), - model.getSubstationLayoutFactory(), - model.getVoltageLevelLayoutFactory(), - initProvider, - model.getStyleProvider(network), - ""); + sldParameters); svgWriter.flush(); metadataWriter.flush(); 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 f4ffdbb..2d96b9a 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 @@ -15,8 +15,8 @@ import com.powsybl.sld.layout.*; import com.powsybl.sld.layout.positionbyclustering.PositionByClustering; -import com.powsybl.sld.layout.positionfromextension.PositionFromExtension; import com.powsybl.sld.library.ComponentLibrary; +import com.powsybl.sld.svg.SvgParameters; import com.powsybl.sld.svg.styles.*; import com.powsybl.sld.svg.styles.iidm.*; import javafx.beans.property.*; @@ -34,21 +34,14 @@ public class SingleLineDiagramModel extends DiagramModel { private static final String UNKNOWN_ITEM = "???"; - private static final String HORIZONTAL_SUBSTATION_LAYOUT = "Horizontal"; - private static final String VERTICAL_SUBSTATION_LAYOUT = "Vertical"; - private static final String CGMES_SUBSTATION_LAYOUT = "CGMES"; - 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"; + // LayoutParameters + private final LayoutParametersBean layoutParametersBean; - // Layout Parameters - private final LayoutParametersBean layoutParameters; + // SvgParameters + private final SvgParametersBean svgParametersBean; // Component library provider private final ObservableList componentLibraries = FXCollections.observableArrayList(); - private final ObjectProperty currentComponentLibrary = new SimpleObjectProperty<>(); // Style provider @@ -60,28 +53,33 @@ public class SingleLineDiagramModel extends DiagramModel { private final BooleanProperty highlightStyleProvider = new SimpleBooleanProperty(); private final BooleanProperty topologicalStyleProvider = new SimpleBooleanProperty(); - // VoltageLevel layout provider - private final Map nameToVoltageLevelLayoutFactoryMap = new TreeMap<>(); // ordered + 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"; - private final ObservableList voltageLevelLayouts = FXCollections.observableArrayList(); + // 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 voltageLevelLayoutFactory; + 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<>(); // CGMES-DL names private final ObservableList cgmesDLDiagramNames = FXCollections.observableArrayList(); - private final StringProperty currentCgmesDLDiagramName = new SimpleStringProperty(); public SingleLineDiagramModel(// Providers ReadOnlyObjectProperty componentLibrary, - ReadOnlyObjectProperty voltageLevelLayoutFactory, + ReadOnlyObjectProperty voltageLevelLayoutFactoryCreator, ReadOnlyObjectProperty substationLayoutFactory, ReadOnlyObjectProperty cgmesDLDiagramName, // Styles @@ -109,22 +107,23 @@ public SingleLineDiagramModel(// Providers Property externCellHeight, Property internCellHeight, Property stackHeight, - BooleanProperty showGrid, - BooleanProperty showInternalNodes, - BooleanProperty drawStraightWires, BooleanProperty disconnectorsOnBus, Property scaleFactor, - BooleanProperty avoidSVGComponentsDuplication, BooleanProperty adaptCellHeightToContent, Property minSpaceBetweenComponents, Property minimumExternCellHeight, Property busBarAlignment, + Property spaceForFeederInfos, + //SvgParameters + BooleanProperty showGrid, + BooleanProperty showInternalNodes, + BooleanProperty drawStraightWires, BooleanProperty centerLabel, BooleanProperty labelDiagonal, Property angleLabel, BooleanProperty addNodesInfos, BooleanProperty feederInfoSymmetry, - Property spaceForFeederInfos, + BooleanProperty avoidSVGComponentsDuplication, Property feederInfosOuterMargin, Property feederInfosIntraMargin ) { @@ -133,14 +132,10 @@ public SingleLineDiagramModel(// Providers // Providers this.currentComponentLibrary.bind(componentLibrary); + this.currentVoltageLevelLayoutFactoryCreator.bind(voltageLevelLayoutFactoryCreator); this.currentSubstationLayoutFactory.bind(substationLayoutFactory); this.currentCgmesDLDiagramName.bind(cgmesDLDiagramName); - this.voltageLevelLayoutFactory = new VoltageLevelLayoutFactoryBean(voltageLevelLayoutFactory, - stackFeeders, - exceptionWhenPatternUnhandled, - handleShunts, - removeFictitiousNodes, - substituteSingularFictitiousNodes); + // Styles this.basicStyleProvider.bindBidirectional(basicStyleProvider); this.nominalStyleProvider.bindBidirectional(nominalStyleProvider); @@ -150,8 +145,8 @@ public SingleLineDiagramModel(// Providers this.highlightStyleProvider.bindBidirectional(highlightStyleProvider); this.topologicalStyleProvider.bindBidirectional(topologicalStyleProvider); - // Layout Parameters - this.layoutParameters = new LayoutParametersBean(diagramPaddingTopBottom, + // LayoutParameters + this.layoutParametersBean = new LayoutParametersBean(diagramPaddingTopBottom, diagramPaddingLeftRight, voltagePaddingTopBottom, voltagePaddingLeftRight, @@ -161,31 +156,32 @@ public SingleLineDiagramModel(// Providers externCellHeight, internCellHeight, stackHeight, - showGrid, - showInternalNodes, - drawStraightWires, disconnectorsOnBus, scaleFactor, - avoidSVGComponentsDuplication, adaptCellHeightToContent, minSpaceBetweenComponents, minimumExternCellHeight, busBarAlignment, + spaceForFeederInfos); + // SvgParameters + this.svgParametersBean = new SvgParametersBean(showGrid, + showInternalNodes, + drawStraightWires, + avoidSVGComponentsDuplication, centerLabel, labelDiagonal, angleLabel, addNodesInfos, feederInfoSymmetry, - spaceForFeederInfos, feederInfosOuterMargin, feederInfosIntraMargin); } public void initProviders() { // VoltageLevelLayouts - nameToVoltageLevelLayoutFactoryMap.put(AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT, new PositionVoltageLevelLayoutFactory(new PositionFromExtension())); - nameToVoltageLevelLayoutFactoryMap.put(AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT, new PositionVoltageLevelLayoutFactory(new PositionByClustering())); - nameToVoltageLevelLayoutFactoryMap.put(RANDOM_VOLTAGELEVEL_LAYOUT, new RandomVoltageLevelLayoutFactory(500, 500)); + 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,14 @@ public void initProviders() { // Set all providers list componentLibraries.setAll(ComponentLibrary.findAll()); substationLayouts.setAll(nameToSubstationLayoutFactoryMap.values()); - voltageLevelLayouts.setAll(nameToVoltageLevelLayoutFactoryMap.values()); + voltageLevelLayouts.setAll(nameToVoltageLevelLayoutFactoryCreatorMap.values()); } public void updateFrom(Network network) { if (network != null) { // VoltageLevelLayouts - nameToVoltageLevelLayoutFactoryMap.put(SMART_VOLTAGELEVEL_LAYOUT, new SmartVoltageLevelLayoutFactory(network)); - nameToVoltageLevelLayoutFactoryMap.put(CGMES_VOLTAGELEVEL_LAYOUT, new CgmesVoltageLevelLayoutFactory(network)); + 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 +208,24 @@ public void updateFrom(Network network) { } // Set all providers list substationLayouts.setAll(nameToSubstationLayoutFactoryMap.values()); - voltageLevelLayouts.setAll(nameToVoltageLevelLayoutFactoryMap.values()); + voltageLevelLayouts.setAll(nameToVoltageLevelLayoutFactoryCreatorMap.values()); } public void addListener(ChangeListener changeListener) { - layoutParameters.addListener(changeListener); - voltageLevelLayoutFactory.addListener(changeListener); + layoutParametersBean.addListener(changeListener); + svgParametersBean.addListener(changeListener); + } + + public LayoutParameters getLayoutParameters() { + return layoutParametersBean.getLayoutParameters(); + } + + public SvgParameters getSvgParameters() { + return svgParametersBean.getSvgParameters(currentCgmesDLDiagramName.get()); + } + + public SvgParametersBean getSvgParametersBean() { + return svgParametersBean; } public ComponentLibrary getComponentLibrary() { @@ -247,27 +255,19 @@ public StyleProvider getStyleProvider(Network network) { return new StyleProvidersList(styles); } - public VoltageLevelLayoutFactory getVoltageLevelLayoutFactory() { - return voltageLevelLayoutFactory.getVoltageLevelLayoutFactory(); + public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator() { + return currentVoltageLevelLayoutFactoryCreator.get(); } public SubstationLayoutFactory getSubstationLayoutFactory() { return currentSubstationLayoutFactory.get(); } - public LayoutParameters getLayoutParameters() { - return layoutParameters.getLayoutParameters(currentCgmesDLDiagramName.get()); - } - - public LayoutParametersBean getLayoutParametersBean() { - return layoutParameters; - } - public ObservableList getComponentLibraries() { return componentLibraries; } - public ObservableList getVoltageLevelLayouts() { + public ObservableList getVoltageLevelLayouts() { return voltageLevelLayouts; } @@ -308,17 +308,17 @@ public SubstationLayoutFactory fromString(String item) { }; } - public StringConverter getVoltageLevelLayoutFactoryStringConverter() { + public StringConverter getVoltageLevelLayoutFactoryCreatorStringConverter() { return new StringConverter<>() { @Override - public String toString(VoltageLevelLayoutFactory object) { - Optional label = nameToVoltageLevelLayoutFactoryMap.keySet().stream().filter(name -> nameToVoltageLevelLayoutFactoryMap.get(name) == object).findFirst(); + public String toString(VoltageLevelLayoutFactoryCreator object) { + Optional label = nameToVoltageLevelLayoutFactoryCreatorMap.keySet().stream().filter(name -> nameToVoltageLevelLayoutFactoryCreatorMap.get(name) == object).findFirst(); return label.orElse(UNKNOWN_ITEM); } @Override - public VoltageLevelLayoutFactory fromString(String item) { - return nameToVoltageLevelLayoutFactoryMap.get(item); + public VoltageLevelLayoutFactoryCreator fromString(String item) { + return nameToVoltageLevelLayoutFactoryCreatorMap.get(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 afaf685..c3bb29f 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 @@ -15,8 +15,8 @@ import com.powsybl.sld.cgmes.layout.CgmesVoltageLevelLayoutFactory; 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.layout.VoltageLevelLayoutFactory; import com.powsybl.sld.library.ComponentLibrary; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; @@ -67,7 +67,7 @@ public class SingleLineDiagramViewController extends AbstractDiagramViewControll public ComboBox substationLayoutComboBox; @FXML - public ComboBox voltageLevelLayoutComboBox; + public ComboBox voltageLevelLayoutComboBox; @FXML public ComboBox cgmesDLDiagramsComboBox; @@ -210,22 +210,24 @@ private void initialize() { externCellHeightSpinner.getValueFactory().valueProperty(), internCellHeightSpinner.getValueFactory().valueProperty(), stackHeightSpinner.getValueFactory().valueProperty(), - showGridCheckBox.selectedProperty(), - showInternalNodesCheckBox.selectedProperty(), - drawStraightWiresCheckBox.selectedProperty(), disconnectorsOnBusCheckBox.selectedProperty(), scaleFactorSpinner.getValueFactory().valueProperty(), - avoidSVGComponentsDuplicationCheckBox.selectedProperty(), adaptCellHeightToContentCheckBox.selectedProperty(), minSpaceBetweenComponentsSpinner.getValueFactory().valueProperty(), minimumExternCellHeightSpinner.getValueFactory().valueProperty(), busBarAlignmentChoice.valueProperty(), + spaceForFeederInfosSpinner.getValueFactory().valueProperty(), + + //SvgParameters + showGridCheckBox.selectedProperty(), + showInternalNodesCheckBox.selectedProperty(), + drawStraightWiresCheckBox.selectedProperty(), centerLabelCheckBox.selectedProperty(), labelDiagonalCheckBox.selectedProperty(), angleLabelSpinner.getValueFactory().valueProperty(), addNodesInfosCheckBox.selectedProperty(), feederInfoSymmetryCheckBox.selectedProperty(), - spaceForFeederInfosSpinner.getValueFactory().valueProperty(), + avoidSVGComponentsDuplicationCheckBox.selectedProperty(), feederInfosOuterMarginSpinner.getValueFactory().valueProperty(), feederInfosIntraMarginSpinner.getValueFactory().valueProperty() ); @@ -244,7 +246,7 @@ private void initialize() { substationLayoutComboBox.getSelectionModel().selectFirst(); // Default selection without Network // VoltageLevel layout voltageLevelLayoutComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getVoltageLevelLayouts())); - voltageLevelLayoutComboBox.setConverter(model.getVoltageLevelLayoutFactoryStringConverter()); + voltageLevelLayoutComboBox.setConverter(model.getVoltageLevelLayoutFactoryCreatorStringConverter()); voltageLevelLayoutComboBox.getSelectionModel().selectFirst(); // Default selection without Network // CGMES-DL Diagrams diff --git a/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SvgParametersBean.java b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SvgParametersBean.java new file mode 100644 index 0000000..661f7b4 --- /dev/null +++ b/diagram-viewer/src/main/java/com/powsybl/diagram/viewer/sld/SvgParametersBean.java @@ -0,0 +1,111 @@ +/** + * 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.svg.SvgParameters; +import javafx.beans.property.*; +import javafx.beans.value.ChangeListener; + +/** + * @author Sophie Frasnedo + */ +public class SvgParametersBean { + + private final BooleanProperty useName = new SimpleBooleanProperty(); + private final BooleanProperty showGrid = new SimpleBooleanProperty(); + private final BooleanProperty showInternalNodes = new SimpleBooleanProperty(); + private final BooleanProperty drawStraightWires = new SimpleBooleanProperty(); + private final BooleanProperty avoidSVGComponentsDuplication = new SimpleBooleanProperty(); + private final BooleanProperty centerLabel = new SimpleBooleanProperty(); + private final BooleanProperty labelDiagonal = new SimpleBooleanProperty(); + private final ObjectPropertyangleLabel = new SimpleObjectProperty<>(); + private final BooleanProperty addNodesInfos = new SimpleBooleanProperty(); + private final BooleanProperty feederInfoSymmetry = new SimpleBooleanProperty(); + private final ObjectPropertyfeederInfosOuterMargin = new SimpleObjectProperty<>(); + private final ObjectPropertyfeederInfosIntraMargin = new SimpleObjectProperty<>(); + + public SvgParametersBean(BooleanProperty showGrid, + BooleanProperty showInternalNodes, + BooleanProperty drawStraightWires, + BooleanProperty avoidSVGComponentsDuplication, + BooleanProperty centerLabel, + BooleanProperty labelDiagonal, + Property angleLabel, + BooleanProperty addNodesInfos, + BooleanProperty feederInfoSymmetry, + Property feederInfosOuterMargin, + Property feederInfosIntraMargin) { + // bind + this.showGrid.bindBidirectional(showGrid); + this.showInternalNodes.bindBidirectional(showInternalNodes); + this.drawStraightWires.bindBidirectional(drawStraightWires); + this.avoidSVGComponentsDuplication.bindBidirectional(avoidSVGComponentsDuplication); + this.centerLabel.bindBidirectional(centerLabel); + this.labelDiagonal.bindBidirectional(labelDiagonal); + this.angleLabel.bindBidirectional(angleLabel); + this.addNodesInfos.bindBidirectional(addNodesInfos); + this.feederInfoSymmetry.bindBidirectional(feederInfoSymmetry); + this.feederInfosOuterMargin.bindBidirectional(feederInfosOuterMargin); + this.feederInfosIntraMargin.bindBidirectional(feederInfosIntraMargin); + + // Initialize + SvgParameters defaultSvgParameters = new SvgParameters() + .setShowGrid(true); + + useName.setValue(defaultSvgParameters.isUseName()); + showGrid.setValue(defaultSvgParameters.isShowGrid()); + showInternalNodes.setValue(defaultSvgParameters.isShowInternalNodes()); + drawStraightWires.setValue(defaultSvgParameters.isDrawStraightWires()); + avoidSVGComponentsDuplication.setValue(defaultSvgParameters.isAvoidSVGComponentsDuplication()); + centerLabel.setValue(defaultSvgParameters.isLabelCentered()); + labelDiagonal.setValue(defaultSvgParameters.isLabelDiagonal()); + angleLabel.setValue(defaultSvgParameters.getAngleLabelShift()); + addNodesInfos.setValue(defaultSvgParameters.isAddNodesInfos()); + feederInfoSymmetry.setValue(defaultSvgParameters.isFeederInfoSymmetry()); + feederInfosOuterMargin.setValue(defaultSvgParameters.getFeederInfosOuterMargin()); + feederInfosIntraMargin.setValue(defaultSvgParameters.getFeederInfosIntraMargin()); + } + + public void bind(BooleanProperty useName) { + this.useName.bindBidirectional(useName); + } + + public void addListener(ChangeListener changeListener) { + this.useName.addListener(changeListener); + this.showGrid.addListener(changeListener); + this.showInternalNodes.addListener(changeListener); + this.drawStraightWires.addListener(changeListener); + this.avoidSVGComponentsDuplication.addListener(changeListener); + this.centerLabel.addListener(changeListener); + this.labelDiagonal.addListener(changeListener); + this.angleLabel.addListener(changeListener); + this.addNodesInfos.addListener(changeListener); + this.feederInfoSymmetry.addListener(changeListener); + this.feederInfosOuterMargin.addListener(changeListener); + this.feederInfosIntraMargin.addListener(changeListener); + } + + public SvgParameters getSvgParameters(String diagramName) { + return new SvgParameters() + .setShowGrid(showGrid.get()) + .setShowInternalNodes(showInternalNodes.get()) + .setDrawStraightWires(drawStraightWires.get()) + .setAvoidSVGComponentsDuplication(avoidSVGComponentsDuplication.get()) + .setLabelCentered(centerLabel.get()) + .setLabelDiagonal(labelDiagonal.get()) + .setAngleLabelShift(angleLabel.get()) + .setAddNodesInfos(addNodesInfos.get()) + .setFeederInfoSymmetry(feederInfoSymmetry.get()) + .setFeederInfosOuterMargin(feederInfosOuterMargin.get()) + .setFeederInfosIntraMargin(feederInfosIntraMargin.get()) + .setDiagramName(diagramName) + // Forced values + .setCssLocation(SvgParameters.CssLocation.INSERTED_IN_SVG) + .setSvgWidthAndHeightAdded(true); + } +} diff --git a/diagram-viewer/src/main/resources/sld/view.fxml b/diagram-viewer/src/main/resources/sld/view.fxml index b92f79a..3575059 100644 --- a/diagram-viewer/src/main/resources/sld/view.fxml +++ b/diagram-viewer/src/main/resources/sld/view.fxml @@ -138,9 +138,6 @@ - - -