Skip to content

Commit

Permalink
Unknown component (#507)
Browse files Browse the repository at this point in the history
* add unknown component in both ConvergenceLibrary and FlatDesignLibrary
* Update reference test files
* Add test for Unknown component

Signed-off-by: Sophie Frasnedo <sophie.frasnedo@rte-france.com>
Co-authored-by: Thomas ADAM <tadam@silicom.fr>
Signed-off-by: BenoitJeanson <benoit.jeanson@rte-france.com>
  • Loading branch information
2 people authored and BenoitJeanson committed May 2, 2023
1 parent 7a86b5b commit 898c34f
Show file tree
Hide file tree
Showing 82 changed files with 1,303 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class ComponentTypeName {
public static final String DANGLING_LINE = "DANGLING_LINE";
public static final String PHASE_SHIFT_TRANSFORMER = "PHASE_SHIFT_TRANSFORMER";
public static final String PHASE_SHIFT_TRANSFORMER_LEG = "PHASE_SHIFT_TRANSFORMER_LEG";
public static final String UNKNOWN_COMPONENT = "UNKNOWN_COMPONENT";

private ComponentTypeName() {
throw new AssertionError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,25 @@ protected List<Element> getElements(Document doc) {
@Override
public Map<String, List<Element>> getSvgElements(String type) {
Objects.requireNonNull(type);
return svgDocuments.get(type);
Map<String, List<Element>> result = svgDocuments.get(type);
if (result == null && isDisplayed(type)) {
result = svgDocuments.get(ComponentTypeName.UNKNOWN_COMPONENT);
}
return result;
}

@Override
public List<AnchorPoint> getAnchorPoints(String type) {
Objects.requireNonNull(type);
Component component = components.get(type);
Component component = getComponent(type);
return component != null ? component.getAnchorPoints()
: Collections.singletonList(new AnchorPoint(0, 0, AnchorOrientation.NONE));
}

@Override
public ComponentSize getSize(String type) {
Objects.requireNonNull(type);
Component component = components.get(type);
Component component = getComponent(type);
return component != null ? component.getSize() : new ComponentSize(0, 0);
}

Expand All @@ -152,15 +156,15 @@ public List<URL> getCssUrls() {
@Override
public Optional<String> getComponentStyleClass(String type) {
Objects.requireNonNull(type);
Component component = components.get(type);
Component component = getComponent(type);
return component != null ? Optional.ofNullable(component.getStyleClass()) : Optional.empty();
}

@Override
public Optional<String> getSubComponentStyleClass(String type, String subComponent) {
Objects.requireNonNull(type);
Objects.requireNonNull(subComponent);
Component component = components.get(type);
Component component = getComponent(type);
if (component != null) {
return component.getSubComponents().stream().filter(sc -> sc.getName().equals(subComponent)).findFirst().map(SubComponent::getStyleClass);
}
Expand All @@ -170,8 +174,25 @@ public Optional<String> getSubComponentStyleClass(String type, String subCompone
@Override
public Map<Orientation, Component.Transformation> getTransformations(String type) {
Objects.requireNonNull(type);
Component component = components.get(type);
Component component = getComponent(type);
return component != null ? component.getTransformations() : Collections.emptyMap();
}

protected Component getComponent(String type) {
Objects.requireNonNull(type);
Component component = components.get(type);
if (component == null && isDisplayed(type)) {
component = components.get(ComponentTypeName.UNKNOWN_COMPONENT);
}
return component;
}

protected boolean isDisplayed(String componentType) {
return !(componentType.equals(ComponentTypeName.PHASE_SHIFT_TRANSFORMER_LEG) ||
componentType.equals(ComponentTypeName.TWO_WINDINGS_TRANSFORMER_LEG) ||
componentType.equals(ComponentTypeName.THREE_WINDINGS_TRANSFORMER_LEG) ||
componentType.equals(ComponentTypeName.LINE) ||
componentType.equals(ComponentTypeName.DANGLING_LINE) ||
componentType.equals(ComponentTypeName.BUSBAR_SECTION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.sld-node {stroke: none; fill: black}
.sld-flash {stroke: none; fill: black}
.sld-lock {stroke: none; fill: black}
.sld-unknown {stroke: none; fill: black}
/* Fonts */
.sld-label {stroke: none; fill: black; font: 8px serif}
.sld-angle, .sld-voltage {font: 10px serif}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,35 @@
} ],
"styleClass" : "sld-lock"
}, {
"type" : "UNKNOWN_COMPONENT",
"anchorPoints" : [ {
"x" : 0.0,
"y" : -5.5,
"orientation" : "VERTICAL"
}, {
"x" : 0.0,
"y" : 5.5,
"orientation" : "VERTICAL"
}, {
"x" : -9.5,
"y" : 0.0,
"orientation" : "HORIZONTAL"
}, {
"x" : 9.5,
"y" : 0.0,
"orientation" : "HORIZONTAL"
} ],
"size" : {
"width" : 20.0,
"height" : 20.0
},
"transformations" : {},
"subComponents" : [ {
"name" : "UNKNOWN_COMPONENT",
"fileName" : "unknown-component.svg"
} ],
"styleClass" : "sld-unknown"
},{
"type" : "ARROW_ACTIVE",
"size" : {
"width" : 10.0,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
.sld-node {stroke: none; fill: black}
.sld-flash {stroke: none; fill: black}
.sld-lock {stroke: none; fill: black}
.sld-unknown {stroke: none; fill: black}
/* Fonts */
.sld-label {stroke: none; fill: black; font: 8px serif}
.sld-angle, .sld-voltage {font: 10px serif}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,36 @@
],
"styleClass": "sld-node"
},
{
"type" : "UNKNOWN_COMPONENT",
"anchorPoints" : [ {
"x" : 0.0,
"y" : -5.5,
"orientation" : "VERTICAL"
}, {
"x" : 0.0,
"y" : 5.5,
"orientation" : "VERTICAL"
}, {
"x" : -9.5,
"y" : 0.0,
"orientation" : "HORIZONTAL"
}, {
"x" : 9.5,
"y" : 0.0,
"orientation" : "HORIZONTAL"
} ],
"size" : {
"width" : 20.0,
"height" : 20.0
},
"transformations" : {},
"subComponents" : [ {
"name" : "UNKNOWN_COMPONENT",
"fileName" : "unknown-component.svg"
} ],
"styleClass" : "sld-unknown"
},
{
"type": "ARROW_ACTIVE",
"size": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.iidm;

import com.powsybl.sld.builders.NetworkGraphBuilder;
import com.powsybl.sld.library.ResourcesComponentLibrary;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Thomas Adam <tadam at silicom.fr>
*/
public class TestUnknownComponent extends AbstractTestCaseIidm {

@BeforeEach
public void setUp() {
layoutParameters.setCellWidth(80);

network = NetworkFactory.createTestCase11Network();
substation = network.getSubstation("subst");
graphBuilder = new NetworkGraphBuilder(network);
}

@Override
protected ResourcesComponentLibrary getResourcesComponentLibrary() {
return new ResourcesComponentLibrary("unknown", "/UnknownLibrary");
}

@Test
public void test() {
layoutParameters.setAddNodesInfos(true);

// build voltage level 1 graph
VoltageLevelGraph g1 = graphBuilder.buildVoltageLevelGraph("vl1");

voltageLevelGraphLayout(g1);

// write SVGs and compare to reference
assertEquals(toString("/TestUnknownLibrary.svg"), toSVG(g1, "/TestUnknownLibrary.svg"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ void test() {
ComponentLibrary cvg = ComponentLibrary.find("Convergence").orElse(null);
assertNotNull(cvg);
assertEquals("Convergence", cvg.getName());
assertEquals(20, cvg.getComponentsSize().size());
assertEquals(21, cvg.getComponentsSize().size());
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 898c34f

Please sign in to comment.