Skip to content

Commit

Permalink
Display Network as ZoneGraph
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <tadam@silicom.fr>
  • Loading branch information
tadam50 committed Mar 14, 2024
1 parent abca67e commit f02c13c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
*/
public class DiagramViewer extends Application {

private static Stage primaryStage;

public void start(Stage primaryStage) throws IOException {
DiagramViewer.primaryStage = primaryStage;

FXMLLoader loader = new FXMLLoader();
loader.setLocation(Objects.requireNonNull(getClass().getResource("/mainView.fxml")));
BorderPane root = loader.load();
Expand All @@ -35,4 +39,8 @@ public void start(Stage primaryStage) throws IOException {
public static void main(String[] args) {
Application.launch(DiagramViewer.class);
}

public static Stage getPrimaryStage() {
return DiagramViewer.primaryStage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
*/
package com.powsybl.diagram.viewer.sld;

import com.powsybl.diagram.viewer.*;
import com.powsybl.diagram.viewer.common.AbstractDiagramController;
import com.powsybl.diagram.viewer.common.ContainerResult;
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.binding.*;
import javafx.beans.property.*;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.scene.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -77,10 +80,6 @@ public static void updateDiagram(Network network,
Container<?> container,
// PositionVoltageLevelLayoutFactory
VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) {

if (container instanceof Network) {
return;
}
Service<ContainerResult> sldService = new Service<>() {
@Override
protected Task<ContainerResult> createTask() {
Expand All @@ -99,12 +98,17 @@ protected ContainerResult call() {
.setSubstationLayoutFactory(model.getSubstationLayoutFactory())
.setStyleProviderFactory(model::getStyleProvider)
.setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

SingleLineDiagram.draw(network, container.getId(),
svgWriter,
metadataWriter,
sldParameters);

if (container instanceof Network network) {
SingleLineDiagram.drawMultiSubstations(network, ((Network) container).getSubstationStream().map(Identifiable::getId).toList(),
svgWriter,
metadataWriter,
sldParameters);
} else {
SingleLineDiagram.draw(network, container.getId(),
svgWriter,
metadataWriter,
sldParameters);
}
svgWriter.flush();
metadataWriter.flush();
result.svgContentProperty().set(svgWriter.toString());
Expand All @@ -118,6 +122,14 @@ protected ContainerResult call() {
};
}
};
// Show waiting cursor during task execution
DiagramViewer.getPrimaryStage().getScene()
.getRoot()
.cursorProperty()
.bind(Bindings.when(sldService.runningProperty())
.then(Cursor.WAIT)
.otherwise(Cursor.DEFAULT)
);

sldService.setOnSucceeded(event -> containerResult.setValue((ContainerResult) event.getSource().getValue()));
sldService.setOnFailed(event -> {
Expand Down

0 comments on commit f02c13c

Please sign in to comment.