Skip to content

Commit

Permalink
Allow PositionVoltageLevelLayoutFactory parametrization (#562)
Browse files Browse the repository at this point in the history
* Add new parameter class for PositionVoltageLevelLayoutFactory parametrization
* Use another PositionVoltageLevelLayoutFactory constructor

---------

Signed-off-by: Sophie Frasnedo <[email protected]>
  • Loading branch information
So-Fras authored Dec 5, 2023
1 parent 76eacce commit 0cc123c
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
package com.powsybl.sld.layout;

import com.powsybl.sld.layout.positionfromextension.PositionFromExtension;
import com.powsybl.sld.model.coordinate.Side;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
Expand All @@ -23,90 +20,36 @@ public class PositionVoltageLevelLayoutFactory implements VoltageLevelLayoutFact

private final PositionFinder positionFinder;

private boolean feederStacked = true;

private boolean removeUnnecessaryFictitiousNodes = true;

private boolean substituteSingularFictitiousByFeederNode = true;

private boolean exceptionIfPatternNotHandled = false;

private boolean handleShunts = false;

private Map<String, Side> busInfoMap = new HashMap<>();
private PositionVoltageLevelLayoutFactoryParameters positionVoltageLevelLayoutFactoryParameters = new PositionVoltageLevelLayoutFactoryParameters();

public PositionVoltageLevelLayoutFactory() {
this(new PositionFromExtension());
}

public PositionVoltageLevelLayoutFactory(PositionFinder positionFinder) {
this.positionFinder = Objects.requireNonNull(positionFinder);
}

public boolean isFeederStacked() {
return feederStacked;
}

public PositionVoltageLevelLayoutFactory setFeederStacked(boolean feederStacked) {
this.feederStacked = feederStacked;
return this;
}

public boolean isExceptionIfPatternNotHandled() {
return exceptionIfPatternNotHandled;
}

public PositionVoltageLevelLayoutFactory setExceptionIfPatternNotHandled(boolean exceptionIfPatternNotHandled) {
this.exceptionIfPatternNotHandled = exceptionIfPatternNotHandled;
return this;
}

public boolean isRemoveUnnecessaryFictitiousNodes() {
return removeUnnecessaryFictitiousNodes;
}

public PositionVoltageLevelLayoutFactory setRemoveUnnecessaryFictitiousNodes(boolean removeUnnecessaryFictitiousNodes) {
this.removeUnnecessaryFictitiousNodes = removeUnnecessaryFictitiousNodes;
return this;
}

public boolean isSubstituteSingularFictitiousByFeederNode() {
return substituteSingularFictitiousByFeederNode;
}

public PositionVoltageLevelLayoutFactory setSubstituteSingularFictitiousByFeederNode(boolean substituteSingularFictitiousByFeederNode) {
this.substituteSingularFictitiousByFeederNode = substituteSingularFictitiousByFeederNode;
return this;
}

public boolean isHandleShunts() {
return handleShunts;
}

public PositionVoltageLevelLayoutFactory setHandleShunts(boolean handleShunts) {
this.handleShunts = handleShunts;
return this;
public PositionVoltageLevelLayoutFactory(PositionVoltageLevelLayoutFactoryParameters positionVoltageLevelLayoutFactoryParameters) {
this(new PositionFromExtension());
this.positionVoltageLevelLayoutFactoryParameters = positionVoltageLevelLayoutFactoryParameters;
}

public Map<String, Side> getBusInfoMap() {
return busInfoMap;
public PositionVoltageLevelLayoutFactory(PositionFinder positionFinder) {
this.positionFinder = Objects.requireNonNull(positionFinder);
}

public PositionVoltageLevelLayoutFactory setBusInfoMap(Map<String, Side> busInfoMap) {
this.busInfoMap = busInfoMap;
return this;
public PositionVoltageLevelLayoutFactory(PositionFinder positionFinder, PositionVoltageLevelLayoutFactoryParameters positionVoltageLevelLayoutFactoryParameters) {
this.positionFinder = Objects.requireNonNull(positionFinder);
this.positionVoltageLevelLayoutFactoryParameters = positionVoltageLevelLayoutFactoryParameters;
}

@Override
public Layout create(VoltageLevelGraph graph) {
// For adapting the graph to the diagram layout
GraphRefiner graphRefiner = new GraphRefiner(removeUnnecessaryFictitiousNodes, substituteSingularFictitiousByFeederNode);
GraphRefiner graphRefiner = new GraphRefiner(positionVoltageLevelLayoutFactoryParameters.isRemoveUnnecessaryFictitiousNodes(), positionVoltageLevelLayoutFactoryParameters.isSubstituteSingularFictitiousByFeederNode());

// For cell detection
ImplicitCellDetector cellDetector = new ImplicitCellDetector(exceptionIfPatternNotHandled);
ImplicitCellDetector cellDetector = new ImplicitCellDetector(positionVoltageLevelLayoutFactoryParameters.isExceptionIfPatternNotHandled());

// For building blocks from cells
BlockOrganizer blockOrganizer = new BlockOrganizer(positionFinder, feederStacked, exceptionIfPatternNotHandled, handleShunts, busInfoMap);
BlockOrganizer blockOrganizer = new BlockOrganizer(positionFinder, positionVoltageLevelLayoutFactoryParameters.isFeederStacked(), positionVoltageLevelLayoutFactoryParameters.isExceptionIfPatternNotHandled(), positionVoltageLevelLayoutFactoryParameters.isHandleShunts(), positionVoltageLevelLayoutFactoryParameters.getBusInfoMap());

return new PositionVoltageLevelLayout(graph, graphRefiner, cellDetector, blockOrganizer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package com.powsybl.sld.layout;

import com.powsybl.sld.model.coordinate.Side;

import java.util.HashMap;
import java.util.Map;

/**
*
* @author Sophie Frasnedo <sophie.frasnedo at rte-france.com>
*/

public class PositionVoltageLevelLayoutFactoryParameters {
private boolean feederStacked = true;
private boolean removeUnnecessaryFictitiousNodes = true;
private boolean substituteSingularFictitiousByFeederNode = true;
private boolean exceptionIfPatternNotHandled = false;
private boolean handleShunts = false;
private Map<String, Side> busInfoMap = new HashMap<>();

public boolean isFeederStacked() {
return feederStacked;
}

public PositionVoltageLevelLayoutFactoryParameters setFeederStacked(boolean feederStacked) {
this.feederStacked = feederStacked;
return this;
}

public boolean isExceptionIfPatternNotHandled() {
return exceptionIfPatternNotHandled;
}

public PositionVoltageLevelLayoutFactoryParameters setExceptionIfPatternNotHandled(boolean exceptionIfPatternNotHandled) {
this.exceptionIfPatternNotHandled = exceptionIfPatternNotHandled;
return this;
}

public boolean isRemoveUnnecessaryFictitiousNodes() {
return removeUnnecessaryFictitiousNodes;
}

public PositionVoltageLevelLayoutFactoryParameters setRemoveUnnecessaryFictitiousNodes(boolean removeUnnecessaryFictitiousNodes) {
this.removeUnnecessaryFictitiousNodes = removeUnnecessaryFictitiousNodes;
return this;
}

public boolean isSubstituteSingularFictitiousByFeederNode() {
return substituteSingularFictitiousByFeederNode;
}

public PositionVoltageLevelLayoutFactoryParameters setSubstituteSingularFictitiousByFeederNode(boolean substituteSingularFictitiousByFeederNode) {
this.substituteSingularFictitiousByFeederNode = substituteSingularFictitiousByFeederNode;
return this;
}

public boolean isHandleShunts() {
return handleShunts;
}

public PositionVoltageLevelLayoutFactoryParameters setHandleShunts(boolean handleShunts) {
this.handleShunts = handleShunts;
return this;
}

public Map<String, Side> getBusInfoMap() {
return busInfoMap;
}

public PositionVoltageLevelLayoutFactoryParameters setBusInfoMap(Map<String, Side> busInfoMap) {
this.busInfoMap = busInfoMap;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ static VoltageLevelLayoutFactoryCreator newPositionVoltageLevelLayoutFactoryCrea
return i -> new PositionVoltageLevelLayoutFactory(positionFinder);
}

static VoltageLevelLayoutFactoryCreator newPositionVoltageLevelLayoutFactoryCreator(PositionFinder positionFinder, PositionVoltageLevelLayoutFactoryParameters positionVoltageLevelLayoutFactoryParameters) {
return i -> new PositionVoltageLevelLayoutFactory(positionFinder, positionVoltageLevelLayoutFactoryParameters);
}

static VoltageLevelLayoutFactoryCreator newPositionVoltageLevelLayoutFactoryCreator() {
return i -> new PositionVoltageLevelLayoutFactory();
}

static VoltageLevelLayoutFactoryCreator newPositionVoltageLevelLayoutFactoryCreator(PositionVoltageLevelLayoutFactoryParameters positionVoltageLevelLayoutFactoryParameters) {
return i -> new PositionVoltageLevelLayoutFactory(positionVoltageLevelLayoutFactoryParameters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.diagram.test.Networks;
import com.powsybl.sld.builders.NetworkGraphBuilder;
import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactory;
import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactoryParameters;
import com.powsybl.sld.library.ResourcesComponentLibrary;
import com.powsybl.sld.model.coordinate.Side;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
Expand Down Expand Up @@ -148,10 +149,11 @@ private void runTest(StyleProvider styleProvider, String filename, LabelProvider
VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph("vl1");

// Run layout
new PositionVoltageLevelLayoutFactory()
PositionVoltageLevelLayoutFactoryParameters positionVoltageLevelLayoutFactoryParameters = new PositionVoltageLevelLayoutFactoryParameters()
.setBusInfoMap(labelProvider.getBusInfoSides(g))
.setExceptionIfPatternNotHandled(true)
.setHandleShunts(true)
.setHandleShunts(true);
new PositionVoltageLevelLayoutFactory(positionVoltageLevelLayoutFactoryParameters)
.create(g)
.run(layoutParameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import com.powsybl.sld.builders.NetworkGraphBuilder;
import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactory;
import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactoryParameters;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -88,9 +89,10 @@ void testHeightFixed() {

VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId());

new PositionVoltageLevelLayoutFactory()
PositionVoltageLevelLayoutFactoryParameters positionVoltageLevelLayoutFactoryParameters = new PositionVoltageLevelLayoutFactoryParameters()
.setFeederStacked(false)
.setRemoveUnnecessaryFictitiousNodes(false)
.setRemoveUnnecessaryFictitiousNodes(false);
new PositionVoltageLevelLayoutFactory(positionVoltageLevelLayoutFactoryParameters)
.create(g)
.run(layoutParameters);

Expand All @@ -104,8 +106,7 @@ void testAdaptHeight() {

VoltageLevelGraph g = graphBuilder.buildVoltageLevelGraph(vl.getId());

new PositionVoltageLevelLayoutFactory()
.setRemoveUnnecessaryFictitiousNodes(false)
new PositionVoltageLevelLayoutFactory(new PositionVoltageLevelLayoutFactoryParameters().setRemoveUnnecessaryFictitiousNodes(false))
.create(g)
.run(layoutParameters);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2019, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.sld.layout;

import com.powsybl.sld.model.coordinate.Side;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Thomas Adam <tadam at silicom.fr>
*/
class PositionVoltageLevelLayoutFactoryParametersTest {

@Test
void test() {
PositionVoltageLevelLayoutFactoryParameters parameters = new PositionVoltageLevelLayoutFactoryParameters();

assertTrue(parameters.isFeederStacked());
parameters.setFeederStacked(false);
assertFalse(parameters.isFeederStacked());

assertTrue(parameters.isRemoveUnnecessaryFictitiousNodes());
parameters.setRemoveUnnecessaryFictitiousNodes(false);
assertFalse(parameters.isRemoveUnnecessaryFictitiousNodes());

assertTrue(parameters.isSubstituteSingularFictitiousByFeederNode());
parameters.setSubstituteSingularFictitiousByFeederNode(false);
assertFalse(parameters.isSubstituteSingularFictitiousByFeederNode());

assertFalse(parameters.isExceptionIfPatternNotHandled());
parameters.setExceptionIfPatternNotHandled(true);
assertTrue(parameters.isExceptionIfPatternNotHandled());

assertFalse(parameters.isHandleShunts());
parameters.setHandleShunts(true);
assertTrue(parameters.isHandleShunts());

assertTrue(parameters.getBusInfoMap().isEmpty());
Map<String, Side> busInfoMap = new HashMap<>();
busInfoMap.put("???", Side.LEFT);
parameters.setBusInfoMap(busInfoMap);
assertFalse(parameters.getBusInfoMap().isEmpty());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.sld.builders.VoltageLevelRawBuilder;
import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactory;
import com.powsybl.sld.layout.PositionVoltageLevelLayoutFactoryParameters;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import com.powsybl.sld.model.nodes.BusNode;
import com.powsybl.sld.model.nodes.FeederNode;
Expand Down Expand Up @@ -68,8 +69,7 @@ void testStacked() {
@Test
void testUnstacked() {
VoltageLevelGraph g = rawGraphBuilder.buildVoltageLevelGraph("vlUnstack");
new PositionVoltageLevelLayoutFactory()
.setFeederStacked(false)
new PositionVoltageLevelLayoutFactory(new PositionVoltageLevelLayoutFactoryParameters().setFeederStacked(false))
.create(g)
.run(layoutParameters);
assertEquals(toString("/TestCase2UnStackedCell.json"), toJson(g, "/TestCase2UnStackedCell.json"));
Expand Down
Loading

0 comments on commit 0cc123c

Please sign in to comment.