Skip to content

Commit

Permalink
Remove useless bean classes creation
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <[email protected]>
  • Loading branch information
tadam50 committed Feb 6, 2024
1 parent 84ca850 commit 666db86
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 326 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
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.property.StringProperty;
import javafx.beans.property.*;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -46,7 +47,8 @@ public void createDiagram(SingleLineDiagramJsHandler jsHandler,
Network network,
SingleLineDiagramModel model,
ContainerResult containerResult,
Container<?> container) {
Container<?> container,
VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) {
super.createDiagram(container, containerResult.svgContentProperty());

// JSHandler management
Expand All @@ -56,7 +58,7 @@ public void createDiagram(SingleLineDiagramJsHandler jsHandler,
sw.setOpen(!sw.isOpen());
StyleProvider styleProvider = model.getStyleProvider(network);
styleProvider.reset();
updateDiagram(network, model, containerResult, container);
updateDiagram(network, model, containerResult, container, voltageLevelLayoutFactoryCreator);
}
});
setUpListenerOnWebViewChanges(jsHandler);
Expand All @@ -66,13 +68,15 @@ public void createDiagram(SingleLineDiagramJsHandler jsHandler,
metadataContent.bind(containerResult.metadataContentProperty());
graphContent.bind(containerResult.jsonContentProperty());

updateDiagram(network, model, containerResult, container);
updateDiagram(network, model, containerResult, container, voltageLevelLayoutFactoryCreator);
}

public static void updateDiagram(Network network,
SingleLineDiagramModel model,
ContainerResult containerResult,
Container<?> container) {
Container<?> container,
// PositionVoltageLevelLayoutFactory
VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator) {
Service<ContainerResult> sldService = new Service<>() {
@Override
protected Task<ContainerResult> createTask() {
Expand All @@ -90,7 +94,7 @@ protected ContainerResult call() {
.setComponentLibrary(model.getComponentLibrary())
.setSubstationLayoutFactory(model.getSubstationLayoutFactory())
.setStyleProviderFactory(model::getStyleProvider)
.setVoltageLevelLayoutFactoryCreator(model.getVoltageLevelLayoutFactoryCreator(network));
.setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

SingleLineDiagram.draw(network, container.getId(),
svgWriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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.CgmesSubstationLayoutFactory;
import com.powsybl.sld.cgmes.layout.*;
import com.powsybl.sld.layout.*;

import com.powsybl.sld.library.ComponentLibrary;
Expand All @@ -30,6 +30,21 @@
*/
public class SingleLineDiagramModel extends DiagramModel {

public enum VoltageLevelLayoutFactoryType {
AUTO_EXTENSIONS, AUTO_WITHOUT_EXTENSIONS_CLUSTERING, CGMES, RANDOM, SMART;

@Override
public String toString() {
return switch (this) {
case SMART -> "Smart";
case AUTO_EXTENSIONS -> "Auto extensions";
case AUTO_WITHOUT_EXTENSIONS_CLUSTERING -> "Auto without extensions Clustering";
case RANDOM -> "Random";
case CGMES -> "CGMES";
};
}
}

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

// LayoutParameters
Expand All @@ -51,15 +66,6 @@ public class SingleLineDiagramModel extends DiagramModel {
private final BooleanProperty highlightStyleProvider = new SimpleBooleanProperty();
private final BooleanProperty topologicalStyleProvider = new SimpleBooleanProperty();

private static final String SMART_VOLTAGELEVEL_LAYOUT = "Smart";
private static final String AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT = "Auto extensions";
private static final String AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT = "Auto without extensions Clustering";
private static final String RANDOM_VOLTAGELEVEL_LAYOUT = "Random";
private static final String CGMES_VOLTAGELEVEL_LAYOUT = "CGMES";

// VoltageLevel layout provider
private final VoltageLevelLayoutFactoryBean voltageLevelLayoutFactoryBean;

// Substation layout provider
private static final String HORIZONTAL_SUBSTATION_LAYOUT = "Horizontal";
private static final String VERTICAL_SUBSTATION_LAYOUT = "Vertical";
Expand All @@ -74,7 +80,6 @@ public class SingleLineDiagramModel extends DiagramModel {

public SingleLineDiagramModel(// Providers
ReadOnlyObjectProperty<ComponentLibrary> componentLibrary,
Property<VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType> voltageLevelLayoutFactoryType,
ReadOnlyObjectProperty<SubstationLayoutFactory> substationLayoutFactory,
ReadOnlyObjectProperty<String> cgmesDLDiagramName,
// Styles
Expand All @@ -85,15 +90,6 @@ public SingleLineDiagramModel(// Providers
Property<Double> animationThreshold2,
BooleanProperty highlightStyleProvider,
BooleanProperty topologicalStyleProvider,
// PositionVoltageLevelLayoutFactory
BooleanProperty stackFeeders,
BooleanProperty exceptionWhenPatternUnhandled,
BooleanProperty handleShunts,
BooleanProperty removeFictitiousNodes,
BooleanProperty substituteSingularFictitiousNodes,
// RandomVoltageLevelLayoutFactory
Property<Double> width,
Property<Double> height,
// LayoutParameters
Property<Double> diagramPaddingTopBottom,
Property<Double> diagramPaddingLeftRight,
Expand Down Expand Up @@ -132,14 +128,6 @@ public SingleLineDiagramModel(// Providers

// Providers
this.currentComponentLibrary.bind(componentLibrary);
this.voltageLevelLayoutFactoryBean = new VoltageLevelLayoutFactoryBean(voltageLevelLayoutFactoryType,
stackFeeders,
exceptionWhenPatternUnhandled,
handleShunts,
removeFictitiousNodes,
substituteSingularFictitiousNodes,
width,
height);
this.currentSubstationLayoutFactory.bind(substationLayoutFactory);
this.currentCgmesDLDiagramName.bind(cgmesDLDiagramName);

Expand Down Expand Up @@ -215,7 +203,6 @@ public void updateFrom(Network network) {
public void addListener(ChangeListener<Object> changeListener) {
layoutParametersBean.addListener(changeListener);
svgParametersBean.addListener(changeListener);
voltageLevelLayoutFactoryBean.addListener(changeListener);
}

public LayoutParameters getLayoutParameters() {
Expand Down Expand Up @@ -257,10 +244,6 @@ public StyleProvider getStyleProvider(Network network) {
return new StyleProvidersList(styles);
}

public VoltageLevelLayoutFactoryCreator getVoltageLevelLayoutFactoryCreator(Network network) {
return voltageLevelLayoutFactoryBean.getVoltageLevelLayoutFactoryCreator(network);
}

public SubstationLayoutFactory getSubstationLayoutFactory() {
return currentSubstationLayoutFactory.get();
}
Expand Down Expand Up @@ -305,53 +288,4 @@ public SubstationLayoutFactory fromString(String item) {
}
};
}

public StringConverter<VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType> getVoltageLevelLayoutFactoryCreatorStringConverter() {
return new StringConverter<>() {
@Override
public String toString(VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType type) {
switch (type) {
case SMART -> {
return SMART_VOLTAGELEVEL_LAYOUT;
}
case AUTO_EXTENSIONS -> {
return AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT;
}
case AUTO_WITHOUT_EXTENSIONS_CLUSTERING -> {
return AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT;
}
case RANDOM -> {
return RANDOM_VOLTAGELEVEL_LAYOUT;
}
case CGMES -> {
return CGMES_VOLTAGELEVEL_LAYOUT;
}
default -> throw new UnsupportedOperationException("This code cannot be reach, missing case '" + type.name() + "'");
}
}

@Override
public VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType fromString(String item) {

switch (item) {
case SMART_VOLTAGELEVEL_LAYOUT -> {
return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.SMART;
}
case AUTO_EXTENSIONS_VOLTAGELEVEL_LAYOUT -> {
return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_EXTENSIONS;
}
case AUTO_WITHOUT_EXTENSIONS_CLUSTERING_VOLTAGELEVEL_LAYOUT -> {
return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.AUTO_WITHOUT_EXTENSIONS_CLUSTERING;
}
case RANDOM_VOLTAGELEVEL_LAYOUT -> {
return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.RANDOM;
}
case CGMES_VOLTAGELEVEL_LAYOUT -> {
return VoltageLevelLayoutFactoryBean.VoltageLevelLayoutFactoryType.CGMES;
}
default -> throw new UnsupportedOperationException("This code cannot be reach, missing case '" + item + "'");
}
}
};
}
}
Loading

0 comments on commit 666db86

Please sign in to comment.