Skip to content

Commit

Permalink
Add matrix in ZoneLayout choices with shape configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Yohann Bachelier <ybachelier@neverhack.com>
  • Loading branch information
YohannBachelierNH committed Jun 3, 2024
1 parent d69b126 commit 275ccd9
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ private void initialize() {
model.networkProperty().addListener((observableValue, oldNetwork, newNetwork) -> {
sldViewController.updateFrom(model.networkProperty());
initSubstationsTree(newNetwork);
try {
sldViewController.initMatrixSubstationList(newNetwork);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});

showNames.selectedProperty().addListener((observable, oldValue, newValue) -> vlTree.refresh());
Expand Down Expand Up @@ -216,6 +221,11 @@ public TreeItem<Container<?>> fromString(String string) {

nadViewController.addListener((observable, oldValue, newValue) -> updateNadDiagrams());
sldViewController.addListener((observable, oldValue, newValue) -> updateSldDiagrams());
sldViewController.updateSldButton.setOnAction(actionEvent -> {
actionEvent.consume();
updateSldDiagrams();
});

}

private void clearSelection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.powsybl.diagram.viewer.sld;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;

public class MatrixShapeViewController {

@FXML
public Label substationName;

@FXML
public Label substationId;

@FXML
public Spinner<Integer> row;

@FXML
public Spinner<Integer> column;

public void setSubstationNameValue(String text) {
this.substationName.setText(text);
}

public String getSubstationNameValue() {
return substationName.getText();
}

public void setRowValue(Integer row) {
this.row.getValueFactory().setValue(row);
}

public Integer getRowValue() {
return row.getValue();
}

public void setColumnValue(Integer column) {
this.column.getValueFactory().setValue(column);
}

public Integer getColumnValue() {
return column.getValue();
}

public void setSubstationIdValue(String substationId) {
this.substationId.setText(substationId);
}

public Label getSubstationIdValue() {
return substationId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,37 @@
*/
package com.powsybl.diagram.viewer.sld;

import com.powsybl.diagram.viewer.*;
import com.powsybl.diagram.viewer.DiagramViewer;
import com.powsybl.diagram.viewer.common.AbstractDiagramController;
import com.powsybl.diagram.viewer.common.ContainerResult;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.Container;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Switch;
import com.powsybl.sld.SingleLineDiagram;
import com.powsybl.sld.SldParameters;
import com.powsybl.sld.layout.HorizontalZoneLayoutFactory;
import com.powsybl.sld.layout.MatrixZoneLayoutFactory;
import com.powsybl.sld.layout.VoltageLevelLayoutFactoryCreator;
import com.powsybl.sld.layout.ZoneLayoutFactory;
import com.powsybl.sld.svg.styles.StyleProvider;
import javafx.beans.binding.*;
import javafx.beans.property.*;
import javafx.concurrent.*;
import javafx.beans.binding.Bindings;
import javafx.beans.property.StringProperty;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.concurrent.Worker;
import javafx.fxml.FXML;
import javafx.scene.*;
import javafx.scene.Cursor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
* @author Thomas Adam <tadam at slicom.fr>
Expand Down Expand Up @@ -101,20 +113,29 @@ protected Task<ContainerResult> createTask() {
@Override
protected ContainerResult call() throws IOException {
ContainerResult result = new ContainerResult();
List<String> substationList = new ArrayList<>();
try (StringWriter svgWriter = new StringWriter();
StringWriter metadataWriter = new StringWriter();
StringWriter jsonWriter = new StringWriter()) {

ZoneLayoutFactory zoneLayoutFactory = model.getZoneLayoutFactory();
if (model.getZoneLayoutFactory() instanceof MatrixZoneLayoutFactory) {
substationList = Arrays.stream(model.getMatrix())
.flatMap(Arrays::stream)
.filter(Predicate.not(String::isEmpty))
.toList();
zoneLayoutFactory = substationList.isEmpty() ?
new HorizontalZoneLayoutFactory() : new MatrixZoneLayoutFactory(model.getMatrix());
}
SldParameters sldParameters = new SldParameters()
.setLayoutParameters(model.getLayoutParameters())
.setSvgParameters(model.getSvgParameters())
.setComponentLibrary(model.getComponentLibrary())
.setSubstationLayoutFactory(model.getSubstationLayoutFactory())
.setStyleProviderFactory(model::getStyleProvider)
.setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator)
.setZoneLayoutFactory(model.getZoneLayoutFactory());
if (container instanceof Network network) {
SingleLineDiagram.drawMultiSubstations(network, ((Network) container).getSubstationStream().map(Identifiable::getId).toList(),
.setZoneLayoutFactory(zoneLayoutFactory);
if (container instanceof Network network && !substationList.isEmpty()) {
SingleLineDiagram.drawMultiSubstations(network, substationList,
svgWriter,
metadataWriter,
sldParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

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.*;
import com.powsybl.sld.cgmes.dl.iidm.extensions.NetworkDiagramData;
import com.powsybl.sld.cgmes.layout.CgmesSubstationLayoutFactory;
import com.powsybl.sld.layout.*;

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 com.powsybl.sld.svg.styles.iidm.HighlightLineStateStyleProvider;
import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -44,7 +44,6 @@ public String toString() {
};
}
}

private static final String UNKNOWN_ITEM = "???";

// LayoutParameters
Expand Down Expand Up @@ -77,6 +76,9 @@ public String toString() {
private static final String HORIZONTAL_ZONE_LAYOUT = "Horizontal";
private static final String VERTICAL_ZONE_LAYOUT = "Vertical";
private static final String MATRIX_ZONE_LAYOUT = "Matrix";
private String[][] matrix = {{}};

private MatrixZoneLayoutFactory matrixZoneLayoutFactory = new MatrixZoneLayoutFactory(this.matrix);
private final Map<String, ZoneLayoutFactory> nameToZoneLayoutFactoryMap = new TreeMap<>(); // ordered
private final ObservableList<ZoneLayoutFactory> zoneLayouts = FXCollections.observableArrayList();
private final ObjectProperty<ZoneLayoutFactory> currentZoneLayoutFactory = new SimpleObjectProperty<>();
Expand Down Expand Up @@ -187,6 +189,7 @@ public void initProviders() {
// zoneLayouts
nameToZoneLayoutFactoryMap.put(HORIZONTAL_ZONE_LAYOUT, new HorizontalZoneLayoutFactory());
nameToZoneLayoutFactoryMap.put(VERTICAL_ZONE_LAYOUT, new VerticalZoneLayoutFactory());
nameToZoneLayoutFactoryMap.put(MATRIX_ZONE_LAYOUT, this.matrixZoneLayoutFactory);

// SubstationLayouts
nameToSubstationLayoutFactoryMap.put(HORIZONTAL_SUBSTATION_LAYOUT, new HorizontalSubstationLayoutFactory());
Expand Down Expand Up @@ -325,4 +328,12 @@ public ZoneLayoutFactory fromString(String item) {
}
};
}

public void setMatrix(String[][] matrix) {
this.matrix = matrix;
}

public String[][] getMatrix() {
return matrix;
}
}
Loading

0 comments on commit 275ccd9

Please sign in to comment.