Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add geographical layout for NAD #114

Merged
merged 9 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions diagram-viewer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-area-diagram</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-cgmes-gl</artifactId>
</dependency>
<!-- __________________________________________________________________________ -->
<!-- SLD -->
<!-- __________________________________________________________________________ -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected Task<Network> createTask() {
@Override
protected Network call() {
Properties properties = new Properties();
properties.put("iidm.import.cgmes.post-processors", "cgmesDLImport");
properties.put("iidm.import.cgmes.post-processors", List.of("cgmesDLImport", "cgmesGLImport"));
properties.put("matpower.import.ignore-base-voltage", "false");
return Network.read(file.toPath(), LocalComputationManager.getDefault(), new ImportConfig(), properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ protected String call() {
NadParameters nadParameters = new NadParameters();
nadParameters.setLayoutParameters(model.getLayoutParameters());
nadParameters.setSvgParameters(model.getSvgParameters());
nadParameters.setLayoutFactory(model.getLayoutFactory(network));
nadParameters.setStyleProviderFactory(model.getStyleProviderFactory());
nadParameters.setLabelProviderFactory(model.getLabelProviderFactory());
NetworkAreaDiagram.draw(network, writer, nadParameters, vls);
return writer.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@
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.iidm.network.*;
import com.powsybl.nad.layout.*;
import com.powsybl.nad.model.*;
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;

import java.util.*;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
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";
static final String GEOGRAPHICAL_LAYOUT = "Geographical";
private static final String TOPOLOGICAL_STYLE_PROVIDER = "Topological";

// Layout Parameters
Expand All @@ -36,11 +34,15 @@ public class NetworkAreaDiagramModel extends DiagramModel {
private final SvgParametersBean svgParameters;

private final IntegerProperty depth = new SimpleIntegerProperty();
private final IntegerProperty geoScalingFactor = new SimpleIntegerProperty();
private final IntegerProperty geoRadiusFactor = new SimpleIntegerProperty();
private final StringProperty labelProvider = new SimpleStringProperty();
private final StringProperty styleProvider = new SimpleStringProperty();
private final StringProperty layoutFactory = new SimpleStringProperty();

public NetworkAreaDiagramModel(ReadOnlyObjectProperty<Integer> depth,
ReadOnlyObjectProperty<Integer> geoScalingFactor,
ReadOnlyObjectProperty<Integer> geoRadiusFactor,
ObjectProperty<String> label,
ObjectProperty<String> style,
ObjectProperty<String> layout,
Expand All @@ -64,6 +66,8 @@ public NetworkAreaDiagramModel(ReadOnlyObjectProperty<Integer> depth,
Property<Double> fixedScale
) {
this.depth.bind(depth);
this.geoScalingFactor.bind(geoScalingFactor);
this.geoRadiusFactor.bind(geoRadiusFactor);
this.labelProvider.bind(label);
this.styleProvider.bind(style);
this.layoutFactory.bind(layout);
Expand Down Expand Up @@ -97,18 +101,24 @@ 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() {
return BASIC_LAYOUT.equals(layoutFactory.getValue()) ? new BasicForceLayoutFactory() : null;
public LayoutFactory getLayoutFactory(Network network) {
return switch (layoutFactory.getValue()) {
case FORCE_LAYOUT -> new BasicForceLayoutFactory();
case GEOGRAPHICAL_LAYOUT -> new GeographicalLayoutFactory(network, geoScalingFactor.getValue(), geoRadiusFactor.getValue(), BasicForceLayout::new);
default -> null;
};
}

public SvgParametersBean getSvgParametersBean() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import com.powsybl.iidm.network.Container;
import com.powsybl.iidm.network.Network;
import com.powsybl.nad.svg.SvgParameters;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.value.ChangeListener;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,6 +35,12 @@ public class NetworkAreaDiagramViewController extends AbstractDiagramViewControl
@FXML
public Spinner<Integer> depthSpinner;
@FXML
public VBox geoParameters;
@FXML
public Spinner<Integer> geoScalingFactorSpinner;
@FXML
public Spinner<Integer> geoRadiusFactorSpinner;
@FXML
public ChoiceBox<String> labelProviderChoice;
@FXML
public ChoiceBox<String> styleProviderChoice;
Expand Down Expand Up @@ -78,6 +86,8 @@ public class NetworkAreaDiagramViewController extends AbstractDiagramViewControl
@FXML
private void initialize() {
model = new NetworkAreaDiagramModel(depthSpinner.valueProperty(),
geoScalingFactorSpinner.valueProperty(),
geoRadiusFactorSpinner.valueProperty(),
labelProviderChoice.valueProperty(),
styleProviderChoice.valueProperty(),
layoutChoice.valueProperty(),
Expand All @@ -98,6 +108,11 @@ private void initialize() {
fixedSizeSpinner.getValueFactory().valueProperty(),
fixedScaleSpinner.getValueFactory().valueProperty()
);

BooleanBinding enableGeoParameters = this.layoutChoice.valueProperty().isEqualTo(NetworkAreaDiagramModel.GEOGRAPHICAL_LAYOUT);
this.geoParameters.visibleProperty().bind(enableGeoParameters);
this.geoParameters.managedProperty().bind(enableGeoParameters);

// Diagram size
this.sizeConstraintChoice.disableProperty().bind(widthHeightAdded.selectedProperty().not());
this.fixedSizeSpinner.visibleProperty().bind(
Expand All @@ -113,6 +128,8 @@ private void initialize() {

public void addListener(ChangeListener<Object> changeListener) {
depthSpinner.valueProperty().addListener(changeListener);
geoScalingFactorSpinner.valueProperty().addListener(changeListener);
geoRadiusFactorSpinner.valueProperty().addListener(changeListener);
labelProviderChoice.valueProperty().addListener(changeListener);
styleProviderChoice.valueProperty().addListener(changeListener);
layoutChoice.valueProperty().addListener(changeListener);
Expand Down
19 changes: 17 additions & 2 deletions diagram-viewer/src/main/resources/nad/view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,28 @@
</Separator>
<GridPane hgap="5" vgap="5">
<Label text="Layout:" GridPane.rowIndex="0"/>
<ChoiceBox fx:id="layoutChoice" GridPane.rowIndex="1" value="Basic">
<ChoiceBox fx:id="layoutChoice" GridPane.rowIndex="1" value="Force layout">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Basic"/>
<String fx:value="Force layout"/>
<String fx:value="Geographical"/>
</FXCollections>
</items>
</ChoiceBox>
<VBox fx:id="geoParameters" GridPane.rowIndex="2">
<Label text="Scaling Factor:"/>
<Spinner fx:id="geoScalingFactorSpinner" editable="true">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory min="1" max="1000000" amountToStepBy="1000" initialValue="150000"/>
</valueFactory>
</Spinner>
<Label text="Radius Factor:"/>
<Spinner fx:id="geoRadiusFactorSpinner" editable="true">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory min="1" max="1000" amountToStepBy="10" initialValue="150"/>
</valueFactory>
</Spinner>
</VBox>
<Label text="LabelProvider:" GridPane.rowIndex="3"/>
<ChoiceBox fx:id="labelProviderChoice" GridPane.rowIndex="4" value="Default">
<items>
Expand Down
Loading