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 33ba3a9..d0b5615 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 @@ -17,12 +17,12 @@ 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.concurrent.*; import javafx.fxml.FXML; import javafx.scene.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.w3c.dom.*; import java.io.IOException; import java.io.StringWriter; @@ -34,6 +34,7 @@ public class SingleLineDiagramController extends AbstractDiagramController { private static final Logger LOGGER = LoggerFactory.getLogger(SingleLineDiagramController.class); + private static Service sldService; private StringProperty metadataContent; private StringProperty graphContent; @@ -64,6 +65,17 @@ public void createDiagram(SingleLineDiagramJsHandler jsHandler, } }); setUpListenerOnWebViewChanges(jsHandler); + // Manage cursor look above WebView + DiagramViewer.getPrimaryStage().getScene().getRoot().cursorProperty().addListener((observable, oldValue, newValue) -> { + if (Worker.State.SUCCEEDED == diagramWebView.getEngine().getLoadWorker().stateProperty().get()) { + Document doc = diagramWebView.getEngine().getDocument(); + Element body = (Element) + doc.getElementsByTagName("body").item(0); + String style = body.getAttribute("style"); + body.setAttribute("style", "cursor: " + ((newValue == Cursor.WAIT) ? "wait" : "default") + ";" + style); + } + }); + containerResult.metadataContentProperty().addListener((obs, oldV, newV) -> jsHandler.setMetadata(containerResult.metadataContentProperty().get())); // Metadata & Graph binding @@ -79,7 +91,10 @@ public static void updateDiagram(Network network, Container container, // PositionVoltageLevelLayoutFactory VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) { - Service sldService = new Service<>() { + if (sldService != null && sldService.isRunning()) { + sldService.cancel(); + } + sldService = new Service<>() { @Override protected Task createTask() { return new Task<>() { @@ -96,7 +111,8 @@ protected ContainerResult call() throws IOException { .setComponentLibrary(model.getComponentLibrary()) .setSubstationLayoutFactory(model.getSubstationLayoutFactory()) .setStyleProviderFactory(model::getStyleProvider) - .setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator); + .setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator) + .setZoneLayoutFactory(model.getZoneLayoutFactory()); if (container instanceof Network network) { SingleLineDiagram.drawMultiSubstations(network, ((Network) container).getSubstationStream().map(Identifiable::getId).toList(), svgWriter, @@ -127,7 +143,7 @@ protected ContainerResult call() throws IOException { .then(Cursor.WAIT) .otherwise(Cursor.DEFAULT) ); - + sldService.setOnCancelled(event -> DiagramViewer.getPrimaryStage().getScene().getRoot().setCursor(Cursor.DEFAULT)); sldService.setOnSucceeded(event -> containerResult.setValue((ContainerResult) event.getSource().getValue())); sldService.setOnFailed(event -> { Throwable exception = event.getSource().getException(); 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 35def98..7993ec2 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 @@ -73,6 +73,13 @@ public String toString() { private final Map nameToSubstationLayoutFactoryMap = new TreeMap<>(); // ordered private final ObservableList substationLayouts = FXCollections.observableArrayList(); private final ObjectProperty currentSubstationLayoutFactory = new SimpleObjectProperty<>(); + // Zone layout provider + 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 final Map nameToZoneLayoutFactoryMap = new TreeMap<>(); // ordered + private final ObservableList zoneLayouts = FXCollections.observableArrayList(); + private final ObjectProperty currentZoneLayoutFactory = new SimpleObjectProperty<>(); // CGMES-DL names private final ObservableList cgmesDLDiagramNames = FXCollections.observableArrayList(); @@ -81,6 +88,7 @@ public String toString() { public SingleLineDiagramModel(// Providers ReadOnlyObjectProperty componentLibrary, ReadOnlyObjectProperty substationLayoutFactory, + ReadOnlyObjectProperty zoneLayoutFactory, ReadOnlyObjectProperty cgmesDLDiagramName, // Styles BooleanProperty basicStyleProvider, @@ -129,6 +137,7 @@ public SingleLineDiagramModel(// Providers // Providers this.currentComponentLibrary.bind(componentLibrary); this.currentSubstationLayoutFactory.bind(substationLayoutFactory); + this.currentZoneLayoutFactory.bind(zoneLayoutFactory); this.currentCgmesDLDiagramName.bind(cgmesDLDiagramName); // Styles @@ -175,6 +184,10 @@ public SingleLineDiagramModel(// Providers } public void initProviders() { + // zoneLayouts + nameToZoneLayoutFactoryMap.put(HORIZONTAL_ZONE_LAYOUT, new HorizontalZoneLayoutFactory()); + nameToZoneLayoutFactoryMap.put(VERTICAL_ZONE_LAYOUT, new VerticalZoneLayoutFactory()); + // SubstationLayouts nameToSubstationLayoutFactoryMap.put(HORIZONTAL_SUBSTATION_LAYOUT, new HorizontalSubstationLayoutFactory()); nameToSubstationLayoutFactoryMap.put(VERTICAL_SUBSTATION_LAYOUT, new VerticalSubstationLayoutFactory()); @@ -182,6 +195,7 @@ public void initProviders() { // Set all providers list componentLibraries.setAll(ComponentLibrary.findAll()); substationLayouts.setAll(nameToSubstationLayoutFactoryMap.values()); + zoneLayouts.setAll(nameToZoneLayoutFactoryMap.values()); } public void updateFrom(Network network) { @@ -248,6 +262,10 @@ public SubstationLayoutFactory getSubstationLayoutFactory() { return currentSubstationLayoutFactory.get(); } + public ZoneLayoutFactory getZoneLayoutFactory() { + return currentZoneLayoutFactory.get(); + } + public ObservableList getComponentLibraries() { return componentLibraries; } @@ -256,6 +274,10 @@ public ObservableList getSubstationLayouts() { return substationLayouts; } + public ObservableList getZoneLayouts() { + return zoneLayouts; + } + public ObservableList getCgmesDLDiagramNames() { return cgmesDLDiagramNames; } @@ -288,4 +310,19 @@ public SubstationLayoutFactory fromString(String item) { } }; } + + public StringConverter getZoneLayoutStringConverter() { + return new StringConverter<>() { + @Override + public String toString(ZoneLayoutFactory object) { + Optional label = nameToZoneLayoutFactoryMap.keySet().stream().filter(name -> nameToZoneLayoutFactoryMap.get(name) == object).findFirst(); + return label.orElse(UNKNOWN_ITEM); + } + + @Override + public ZoneLayoutFactory fromString(String item) { + return nameToZoneLayoutFactoryMap.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 9a4642d..1f83b4f 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 @@ -69,6 +69,9 @@ public class SingleLineDiagramViewController extends AbstractDiagramViewControll @FXML public ComboBox substationLayoutComboBox; + @FXML + public ComboBox zoneLayoutComboBox; + @FXML public ChoiceBox voltageLevelLayoutComboBox; @@ -192,6 +195,7 @@ private void initialize() { // Providers componentLibraryComboBox.valueProperty(), substationLayoutComboBox.valueProperty(), + zoneLayoutComboBox.valueProperty(), cgmesDLDiagramsComboBox.valueProperty(), // - Styles basicStyleProviderCheckBox.selectedProperty(), @@ -248,6 +252,10 @@ private void initialize() { substationLayoutComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getSubstationLayouts())); substationLayoutComboBox.setConverter(model.getSubstationLayoutStringConverter()); substationLayoutComboBox.getSelectionModel().selectFirst(); // Default selection without Network + // Zone layout + zoneLayoutComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getZoneLayouts())); + zoneLayoutComboBox.setConverter(model.getZoneLayoutStringConverter()); + zoneLayoutComboBox.getSelectionModel().selectFirst(); // Default selection without Network // CGMES-DL Diagrams cgmesDLDiagramsComboBox.itemsProperty().bind(Bindings.createObjectBinding(() -> model.getCgmesDLDiagramNames())); @@ -271,6 +279,7 @@ private void initialize() { public void addListener(ChangeListener changeListener) { componentLibraryComboBox.valueProperty().addListener(changeListener); substationLayoutComboBox.valueProperty().addListener(changeListener); + zoneLayoutComboBox.valueProperty().addListener(changeListener); cgmesDLDiagramsComboBox.valueProperty().addListener(changeListener); basicStyleProviderCheckBox.selectedProperty().addListener(changeListener); diff --git a/diagram-viewer/src/main/resources/sld/view.fxml b/diagram-viewer/src/main/resources/sld/view.fxml index d55ec62..742b650 100644 --- a/diagram-viewer/src/main/resources/sld/view.fxml +++ b/diagram-viewer/src/main/resources/sld/view.fxml @@ -61,6 +61,8 @@ +