From 5a8f1dee1b8f0bc7450aa9d3d8d056095dc3019b Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Mon, 15 Apr 2024 16:12:05 +0200 Subject: [PATCH 1/8] Add to NadParameters : LayoutFactory, StyleProvider & LabelProvider Signed-off-by: Thomas ADAM --- .../nad/NetworkAreaDiagramController.java | 3 +++ .../viewer/nad/NetworkAreaDiagramModel.java | 19 ++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) 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 0305690..bd2530d 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 @@ -59,6 +59,9 @@ protected String call() { NadParameters nadParameters = new NadParameters(); nadParameters.setLayoutParameters(model.getLayoutParameters()); nadParameters.setSvgParameters(model.getSvgParameters()); + nadParameters.setLayoutFactory(model.getLayoutFactory()); + nadParameters.setStyleProviderFactory(model.getStyleProviderFactory()); + nadParameters.setLabelProviderFactory(model.getLabelProviderFactory()); NetworkAreaDiagram.draw(network, writer, nadParameters, vls); return writer.toString(); } 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 a8d12f4..03e0186 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 @@ -8,16 +8,11 @@ package com.powsybl.diagram.viewer.nad; import com.powsybl.diagram.viewer.common.DiagramModel; -import com.powsybl.iidm.network.Network; import com.powsybl.nad.layout.BasicForceLayoutFactory; import com.powsybl.nad.layout.LayoutFactory; import com.powsybl.nad.layout.LayoutParameters; -import com.powsybl.nad.svg.LabelProvider; -import com.powsybl.nad.svg.StyleProvider; import com.powsybl.nad.svg.SvgParameters; -import com.powsybl.nad.svg.iidm.DefaultLabelProvider; -import com.powsybl.nad.svg.iidm.NominalVoltageStyleProvider; -import com.powsybl.nad.svg.iidm.TopologicalStyleProvider; +import com.powsybl.nad.svg.iidm.*; import javafx.beans.property.*; import javafx.beans.value.ChangeListener; @@ -97,14 +92,16 @@ public LayoutParameters getLayoutParameters() { return layoutParametersBean.getLayoutParameters(); } - public LabelProvider getLabelProvider(Network network) { - return DEFAULT_LABEL_PROVIDER.equals(labelProvider.getValue()) ? new DefaultLabelProvider(network, getSvgParameters()) : null; + public LabelProviderFactory getLabelProviderFactory() { + return DEFAULT_LABEL_PROVIDER.equals(labelProvider.getValue()) + ? DefaultLabelProvider::new + : null; } - public StyleProvider getStyleProvider(Network network) { + public StyleProviderFactory getStyleProviderFactory() { return TOPOLOGICAL_STYLE_PROVIDER.equals(styleProvider.getValue()) - ? new TopologicalStyleProvider(network) - : new NominalVoltageStyleProvider(network); + ? TopologicalStyleProvider::new + : NominalVoltageStyleProvider::new; } public LayoutFactory getLayoutFactory() { From 0b304bae4fe739f15e8021a2345b724f049c2cc8 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Mon, 15 Apr 2024 16:24:30 +0200 Subject: [PATCH 2/8] Add Nad Geographical Layout Signed-off-by: Thomas ADAM --- .../viewer/nad/NetworkAreaDiagramController.java | 2 +- .../viewer/nad/NetworkAreaDiagramModel.java | 16 +++++++++++----- diagram-viewer/src/main/resources/nad/view.fxml | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) 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 bd2530d..caf98b1 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 @@ -59,7 +59,7 @@ protected String call() { NadParameters nadParameters = new NadParameters(); nadParameters.setLayoutParameters(model.getLayoutParameters()); nadParameters.setSvgParameters(model.getSvgParameters()); - nadParameters.setLayoutFactory(model.getLayoutFactory()); + nadParameters.setLayoutFactory(model.getLayoutFactory(network)); nadParameters.setStyleProviderFactory(model.getStyleProviderFactory()); nadParameters.setLabelProviderFactory(model.getLabelProviderFactory()); NetworkAreaDiagram.draw(network, writer, nadParameters, vls); 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 03e0186..68c8150 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 @@ -8,9 +8,8 @@ package com.powsybl.diagram.viewer.nad; import com.powsybl.diagram.viewer.common.DiagramModel; -import com.powsybl.nad.layout.BasicForceLayoutFactory; -import com.powsybl.nad.layout.LayoutFactory; -import com.powsybl.nad.layout.LayoutParameters; +import com.powsybl.iidm.network.*; +import com.powsybl.nad.layout.*; import com.powsybl.nad.svg.SvgParameters; import com.powsybl.nad.svg.iidm.*; import javafx.beans.property.*; @@ -22,6 +21,8 @@ public class NetworkAreaDiagramModel extends DiagramModel { private static final String DEFAULT_LABEL_PROVIDER = "Default"; private static final String BASIC_LAYOUT = "Basic"; + private static final String FIXED_LAYOUT = "Fixed"; + private static final String GEOGRAPHICAL_LAYOUT = "Geographical"; private static final String TOPOLOGICAL_STYLE_PROVIDER = "Topological"; // Layout Parameters @@ -104,8 +105,13 @@ public StyleProviderFactory getStyleProviderFactory() { : NominalVoltageStyleProvider::new; } - public LayoutFactory getLayoutFactory() { - return BASIC_LAYOUT.equals(layoutFactory.getValue()) ? new BasicForceLayoutFactory() : null; + public LayoutFactory getLayoutFactory(Network network) { + return switch (layoutFactory.getValue()) { + case BASIC_LAYOUT -> new BasicForceLayoutFactory(); + //case FIXED_LAYOUT -> new FixedLayoutFactory(); + case GEOGRAPHICAL_LAYOUT -> new GeographicalLayoutFactory(network); + default -> null; + }; } public SvgParametersBean getSvgParametersBean() { diff --git a/diagram-viewer/src/main/resources/nad/view.fxml b/diagram-viewer/src/main/resources/nad/view.fxml index 910fd6b..6b16a95 100644 --- a/diagram-viewer/src/main/resources/nad/view.fxml +++ b/diagram-viewer/src/main/resources/nad/view.fxml @@ -42,6 +42,8 @@ + + From d02c30e94f592a1a0c34eabde1dcb26abe258bf5 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Mon, 15 Apr 2024 16:35:01 +0200 Subject: [PATCH 3/8] Add Nad Fixed Layout (with empty positions) Signed-off-by: Thomas ADAM --- .../diagram/viewer/nad/NetworkAreaDiagramModel.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 68c8150..f2e3bfa 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 @@ -10,11 +10,14 @@ import com.powsybl.diagram.viewer.common.DiagramModel; import com.powsybl.iidm.network.*; import com.powsybl.nad.layout.*; +import com.powsybl.nad.model.*; import com.powsybl.nad.svg.SvgParameters; import com.powsybl.nad.svg.iidm.*; import javafx.beans.property.*; import javafx.beans.value.ChangeListener; +import java.util.*; + /** * @author Florian Dupuy */ @@ -106,9 +109,11 @@ public StyleProviderFactory getStyleProviderFactory() { } public LayoutFactory getLayoutFactory(Network network) { + // FIXME : user must be able to customize positions + Map initialPositions = new HashMap<>(); return switch (layoutFactory.getValue()) { case BASIC_LAYOUT -> new BasicForceLayoutFactory(); - //case FIXED_LAYOUT -> new FixedLayoutFactory(); + case FIXED_LAYOUT -> new FixedLayoutFactory(initialPositions); case GEOGRAPHICAL_LAYOUT -> new GeographicalLayoutFactory(network); default -> null; }; From 6b33e5c95c51b25f152ed4b8e4afb98e12fe62f3 Mon Sep 17 00:00:00 2001 From: Thomas ADAM Date: Thu, 25 Apr 2024 15:11:24 +0200 Subject: [PATCH 4/8] Taking into account PR comments Signed-off-by: Thomas ADAM --- .../powsybl/diagram/viewer/nad/NetworkAreaDiagramModel.java | 4 ++-- diagram-viewer/src/main/resources/nad/view.fxml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 f2e3bfa..5257fd2 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 @@ -23,7 +23,7 @@ */ public class NetworkAreaDiagramModel extends DiagramModel { private static final String DEFAULT_LABEL_PROVIDER = "Default"; - private static final String BASIC_LAYOUT = "Basic"; + private static final String FORCE_LAYOUT = "Force layout"; private static final String FIXED_LAYOUT = "Fixed"; private static final String GEOGRAPHICAL_LAYOUT = "Geographical"; private static final String TOPOLOGICAL_STYLE_PROVIDER = "Topological"; @@ -112,7 +112,7 @@ public LayoutFactory getLayoutFactory(Network network) { // FIXME : user must be able to customize positions Map initialPositions = new HashMap<>(); return switch (layoutFactory.getValue()) { - case BASIC_LAYOUT -> new BasicForceLayoutFactory(); + case FORCE_LAYOUT -> new BasicForceLayoutFactory(); case FIXED_LAYOUT -> new FixedLayoutFactory(initialPositions); case GEOGRAPHICAL_LAYOUT -> new GeographicalLayoutFactory(network); default -> null; diff --git a/diagram-viewer/src/main/resources/nad/view.fxml b/diagram-viewer/src/main/resources/nad/view.fxml index 6b16a95..f97e3d5 100644 --- a/diagram-viewer/src/main/resources/nad/view.fxml +++ b/diagram-viewer/src/main/resources/nad/view.fxml @@ -38,10 +38,10 @@