|
| 1 | +/** |
| 2 | + * Copyright (c) 2025, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + * SPDX-License-Identifier: MPL-2.0 |
| 7 | + */ |
| 8 | +package com.powsybl.nad.svg; |
| 9 | + |
| 10 | +import com.powsybl.diagram.test.Networks; |
| 11 | +import com.powsybl.iidm.network.Network; |
| 12 | +import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory; |
| 13 | +import com.powsybl.nad.AbstractTest; |
| 14 | +import com.powsybl.nad.layout.LayoutParameters; |
| 15 | +import com.powsybl.nad.svg.iidm.TopologicalStyleProvider; |
| 16 | +import org.junit.jupiter.api.BeforeEach; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
| 19 | +import java.util.HashMap; |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author Christian Biasuzzi {@literal <christian.biasuzzi at soft.it>} |
| 25 | + */ |
| 26 | +class CustomLabelProviderTest extends AbstractTest { |
| 27 | + |
| 28 | + LabelProvider labelProvider; |
| 29 | + |
| 30 | + @BeforeEach |
| 31 | + void setup() { |
| 32 | + setLayoutParameters(new LayoutParameters()); |
| 33 | + |
| 34 | + //Note: SvgParameters EdgeNameDisplayed, VoltageLevelDetails, and BusLegend must be true, |
| 35 | + // for the edge names, the VL descriptions plus VL details, and bus descriptions to be rendered |
| 36 | + setSvgParameters(new SvgParameters() |
| 37 | + .setSvgWidthAndHeightAdded(true) |
| 38 | + .setFixedWidth(800) |
| 39 | + .setEdgeNameDisplayed(true) |
| 40 | + .setVoltageLevelDetails(true) |
| 41 | + .setBusLegend(true)); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + protected StyleProvider getStyleProvider(Network network) { |
| 46 | + return new TopologicalStyleProvider(network); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + protected LabelProvider getLabelProvider(Network network) { |
| 51 | + return labelProvider; |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void testCustomLabelProvider() { |
| 56 | + Network network = Networks.createNodeBreakerNetworkWithBranchStatus("TestNodeDecorators", "test"); |
| 57 | + |
| 58 | + Map<String, CustomLabelProvider.BranchLabels> branchLabels = new HashMap<>(); |
| 59 | + branchLabels.put("L12", new CustomLabelProvider.BranchLabels("L1_1", "L1", "L1_2", EdgeInfo.Direction.IN, EdgeInfo.Direction.IN)); |
| 60 | + branchLabels.put("T12", new CustomLabelProvider.BranchLabels("TWT1_1", "TWT1", "TWT1_2", null, null)); |
| 61 | + branchLabels.put("L11", new CustomLabelProvider.BranchLabels(null, "L2", null, EdgeInfo.Direction.IN, EdgeInfo.Direction.IN)); |
| 62 | + branchLabels.put("T11", new CustomLabelProvider.BranchLabels(null, "TWT2", "TWT2_2", null, EdgeInfo.Direction.OUT)); |
| 63 | + |
| 64 | + Map<String, CustomLabelProvider.ThreeWtLabels> threeWtLabels = new HashMap<>(); |
| 65 | + |
| 66 | + Map<String, String> busDescriptions = new HashMap<>(); |
| 67 | + busDescriptions.put("VL1_10", "VL1 10"); |
| 68 | + busDescriptions.put("VL2_30", "VL2 30"); |
| 69 | + |
| 70 | + Map<String, List<String>> vlDescriptions = new HashMap<>(); |
| 71 | + vlDescriptions.put("VL1", List.of("VL1 description1", "VL1 description2")); |
| 72 | + vlDescriptions.put("VL2", List.of("VL2 description1")); |
| 73 | + |
| 74 | + Map<String, List<String>> vlDetails = new HashMap<>(); |
| 75 | + vlDetails.put("VL2", List.of("VL2 details1", "VL2 details2")); |
| 76 | + |
| 77 | + labelProvider = new CustomLabelProvider(branchLabels, threeWtLabels, busDescriptions, vlDescriptions, vlDetails); |
| 78 | + |
| 79 | + assertSvgEquals("/custom_label_provider.svg", network); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + void testCustomLabelProvider3wt() { |
| 84 | + Network network = ThreeWindingsTransformerNetworkFactory.create(); |
| 85 | + |
| 86 | + Map<String, CustomLabelProvider.BranchLabels> branchLabels = new HashMap<>(); |
| 87 | + Map<String, CustomLabelProvider.ThreeWtLabels> threeWtLabels = new HashMap<>(); |
| 88 | + threeWtLabels.put("3WT", new CustomLabelProvider.ThreeWtLabels("SIDE1", "SIDE2", "SIDE3", EdgeInfo.Direction.IN, EdgeInfo.Direction.OUT, EdgeInfo.Direction.IN)); |
| 89 | + |
| 90 | + Map<String, String> busDescriptions = new HashMap<>(); |
| 91 | + busDescriptions.put("VL_132_0", "VL1 132"); |
| 92 | + busDescriptions.put("VL_33_0", "VL2 33"); |
| 93 | + busDescriptions.put("VL_11_0", "VL2 11"); |
| 94 | + |
| 95 | + Map<String, List<String>> vlDescriptions = new HashMap<>(); |
| 96 | + vlDescriptions.put("VL_132", List.of("VL 132 description1", "VL1 132 description2")); |
| 97 | + vlDescriptions.put("VL_33", List.of("VL 33 description1")); |
| 98 | + vlDescriptions.put("VL_11", List.of("VL 11 description1")); |
| 99 | + |
| 100 | + Map<String, List<String>> vlDetails = new HashMap<>(); |
| 101 | + vlDetails.put("VL_132", List.of("VL 132 details1")); |
| 102 | + vlDetails.put("VL_33", List.of("VL 33 details1", "VL 33 details2")); |
| 103 | + vlDetails.put("VL_11", List.of("VL 1 details1")); |
| 104 | + |
| 105 | + labelProvider = new CustomLabelProvider(branchLabels, threeWtLabels, busDescriptions, vlDescriptions, vlDetails); |
| 106 | + |
| 107 | + assertSvgEquals("/custom_label_provider_3wt.svg", network); |
| 108 | + } |
| 109 | + |
| 110 | +} |
0 commit comments