Skip to content

Commit

Permalink
Add Horizontal & Vertical Zone layout choice
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <tadam@silicom.fr>
  • Loading branch information
tadam50 committed Apr 5, 2024
1 parent 0e96116 commit ff2c88d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +34,7 @@ public class SingleLineDiagramController extends AbstractDiagramController {

private static final Logger LOGGER = LoggerFactory.getLogger(SingleLineDiagramController.class);

private static Service<ContainerResult> sldService;
private StringProperty metadataContent;
private StringProperty graphContent;

Expand Down Expand Up @@ -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
Expand All @@ -79,7 +91,10 @@ public static void updateDiagram(Network network,
Container<?> container,
// PositionVoltageLevelLayoutFactory
VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) {
Service<ContainerResult> sldService = new Service<>() {
if (sldService != null && sldService.isRunning()) {
sldService.cancel();
}
sldService = new Service<>() {
@Override
protected Task<ContainerResult> createTask() {
return new Task<>() {
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public String toString() {
private final Map<String, SubstationLayoutFactory> nameToSubstationLayoutFactoryMap = new TreeMap<>(); // ordered
private final ObservableList<SubstationLayoutFactory> substationLayouts = FXCollections.observableArrayList();
private final ObjectProperty<SubstationLayoutFactory> 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<String, ZoneLayoutFactory> nameToZoneLayoutFactoryMap = new TreeMap<>(); // ordered
private final ObservableList<ZoneLayoutFactory> zoneLayouts = FXCollections.observableArrayList();
private final ObjectProperty<ZoneLayoutFactory> currentZoneLayoutFactory = new SimpleObjectProperty<>();

// CGMES-DL names
private final ObservableList<String> cgmesDLDiagramNames = FXCollections.observableArrayList();
Expand All @@ -81,6 +88,7 @@ public String toString() {
public SingleLineDiagramModel(// Providers
ReadOnlyObjectProperty<ComponentLibrary> componentLibrary,
ReadOnlyObjectProperty<SubstationLayoutFactory> substationLayoutFactory,
ReadOnlyObjectProperty<ZoneLayoutFactory> zoneLayoutFactory,
ReadOnlyObjectProperty<String> cgmesDLDiagramName,
// Styles
BooleanProperty basicStyleProvider,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -175,13 +184,18 @@ 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());

// Set all providers list
componentLibraries.setAll(ComponentLibrary.findAll());
substationLayouts.setAll(nameToSubstationLayoutFactoryMap.values());
zoneLayouts.setAll(nameToZoneLayoutFactoryMap.values());
}

public void updateFrom(Network network) {
Expand Down Expand Up @@ -248,6 +262,10 @@ public SubstationLayoutFactory getSubstationLayoutFactory() {
return currentSubstationLayoutFactory.get();
}

public ZoneLayoutFactory getZoneLayoutFactory() {
return currentZoneLayoutFactory.get();
}

public ObservableList<ComponentLibrary> getComponentLibraries() {
return componentLibraries;
}
Expand All @@ -256,6 +274,10 @@ public ObservableList<SubstationLayoutFactory> getSubstationLayouts() {
return substationLayouts;
}

public ObservableList<ZoneLayoutFactory> getZoneLayouts() {
return zoneLayouts;
}

public ObservableList<String> getCgmesDLDiagramNames() {
return cgmesDLDiagramNames;
}
Expand Down Expand Up @@ -288,4 +310,19 @@ public SubstationLayoutFactory fromString(String item) {
}
};
}

public StringConverter<ZoneLayoutFactory> getZoneLayoutStringConverter() {
return new StringConverter<>() {
@Override
public String toString(ZoneLayoutFactory object) {
Optional<String> 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);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public class SingleLineDiagramViewController extends AbstractDiagramViewControll
@FXML
public ComboBox<SubstationLayoutFactory> substationLayoutComboBox;

@FXML
public ComboBox<ZoneLayoutFactory> zoneLayoutComboBox;

@FXML
public ChoiceBox<SingleLineDiagramModel.VoltageLevelLayoutFactoryType> voltageLevelLayoutComboBox;

Expand Down Expand Up @@ -192,6 +195,7 @@ private void initialize() {
// Providers
componentLibraryComboBox.valueProperty(),
substationLayoutComboBox.valueProperty(),
zoneLayoutComboBox.valueProperty(),
cgmesDLDiagramsComboBox.valueProperty(),
// - Styles
basicStyleProviderCheckBox.selectedProperty(),
Expand Down Expand Up @@ -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()));
Expand All @@ -271,6 +279,7 @@ private void initialize() {
public void addListener(ChangeListener<Object> changeListener) {
componentLibraryComboBox.valueProperty().addListener(changeListener);
substationLayoutComboBox.valueProperty().addListener(changeListener);
zoneLayoutComboBox.valueProperty().addListener(changeListener);
cgmesDLDiagramsComboBox.valueProperty().addListener(changeListener);

basicStyleProviderCheckBox.selectedProperty().addListener(changeListener);
Expand Down
2 changes: 2 additions & 0 deletions diagram-viewer/src/main/resources/sld/view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
</valueFactory>
</Spinner>
</HBox>
<Label text="Zone Layout:"/>
<ComboBox fx:id="zoneLayoutComboBox"/>
<Label text="Substation Layout:"/>
<ComboBox fx:id="substationLayoutComboBox"/>
<Label text="VoltageLevel Layout:"/>
Expand Down

0 comments on commit ff2c88d

Please sign in to comment.