Skip to content

Commit 9e003c9

Browse files
authored
Merge branch 'main' into nro/licenses
2 parents 51d3db6 + ce13121 commit 9e003c9

13 files changed

Lines changed: 367 additions & 21 deletions

File tree

.github/workflows/fork-build-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ jobs:
2323
with:
2424
distribution: 'temurin'
2525
java-version: '21'
26+
cache: 'maven'
2627

2728
- name: Build with Maven (Ubuntu)
2829
if: matrix.os == 'ubuntu-latest'
29-
run: ./mvnw --batch-mode -P jacoco,checks install
30+
run: ./mvnw -B -ntp -Pjacoco install
3031

3132
- name: Build with Maven (Windows)
3233
if: matrix.os == 'windows-latest'
33-
run: mvnw.cmd --batch-mode install
34+
run: mvnw.cmd -B -ntp verify -Dpowsybl.checks.skip=true
3435
shell: cmd
3536

3637
- name: Build with Maven (MacOS)
3738
if: matrix.os == 'macos-latest'
38-
run: ./mvnw --batch-mode install
39+
run: ./mvnw -B -ntp verify -Dpowsybl.checks.skip=true
3940

4041
- name: Regroup dependencies in target folders
4142
if: matrix.os == 'ubuntu-latest'

.github/workflows/fork-sonar.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
with:
8383
distribution: 'temurin'
8484
java-version: '21'
85+
cache: 'maven'
8586

8687
- name: Download artifact
8788
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1

.github/workflows/maven.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,33 @@ jobs:
2424
steps:
2525
- name: Checkout sources
2626
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
27+
with:
28+
fetch-depth: 0
2729

2830
- name: Set up JDK 21
2931
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
3032
with:
3133
distribution: 'temurin'
32-
java-version: 21
34+
java-version: '21'
35+
cache: 'maven'
3336

3437
- name: Build with Maven (Ubuntu)
3538
if: matrix.os == 'ubuntu-latest'
36-
run: ./mvnw --batch-mode -P jacoco,checks install
39+
run: ./mvnw -B -ntp -Pjacoco install
3740

3841
- name: Build with Maven (Windows)
3942
if: matrix.os == 'windows-latest'
40-
run: mvnw.cmd --batch-mode install
43+
run: mvnw.cmd -B -ntp verify -Dpowsybl.checks.skip=true
4144
shell: cmd
4245

4346
- name: Build with Maven (MacOS)
4447
if: matrix.os == 'macos-latest'
45-
run: ./mvnw --batch-mode install
48+
run: ./mvnw -B -ntp verify -Dpowsybl.checks.skip=true
4649

4750
- name: Run SonarCloud analysis
4851
if: matrix.os == 'ubuntu-latest'
4952
run: >
50-
./mvnw --batch-mode -Pjacoco verify sonar:sonar
53+
./mvnw -B -ntp -DskipTests sonar:sonar
5154
-Dsonar.host.url=https://sonarcloud.io
5255
-Dsonar.organization=powsybl-ci-github
5356
-Dsonar.projectKey=com.powsybl:powsybl-diagram

network-area-diagram/src/main/java/com/powsybl/nad/svg/EdgeInfo.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,27 @@ public class EdgeInfo {
2929
private final Direction arrowDirection;
3030
private final String labelA;
3131
private final String labelB;
32+
private final String componentType;
3233

3334
public EdgeInfo(String infoTypeA, String infoTypeB, Direction arrowDirection, String labelA, String labelB) {
35+
this(infoTypeA, infoTypeB, arrowDirection, labelA, labelB, null);
36+
}
37+
38+
public EdgeInfo(String infoTypeA, String infoTypeB, Direction arrowDirection, String labelA, String labelB, String componentType) {
3439
this.infoTypeB = infoTypeB;
3540
this.infoTypeA = infoTypeA;
3641
this.arrowDirection = arrowDirection;
3742
this.labelA = labelA;
3843
this.labelB = labelB;
44+
this.componentType = componentType;
3945
}
4046

4147
public EdgeInfo(String infoTypeA, String infoTypeB, double referenceValue, String labelA, String labelB) {
42-
this(infoTypeA, infoTypeB, getArrowDirection(referenceValue), labelA, labelB);
48+
this(infoTypeA, infoTypeB, getArrowDirection(referenceValue), labelA, labelB, null);
49+
}
50+
51+
public EdgeInfo(String infoTypeA, String infoTypeB, double referenceValue, String labelA, String labelB, String componentType) {
52+
this(infoTypeA, infoTypeB, getArrowDirection(referenceValue), labelA, labelB, componentType);
4353
}
4454

4555
private static Direction getArrowDirection(double value) {
@@ -77,6 +87,10 @@ public Optional<String> getLabelB() {
7787
return Optional.ofNullable(labelB);
7888
}
7989

90+
public Optional<String> getComponentType() {
91+
return Optional.ofNullable(componentType);
92+
}
93+
8094
/**
8195
* Returns the main info type.
8296
* @return the main info type. By default, the info type of the side 2.

network-area-diagram/src/main/java/com/powsybl/nad/svg/SvgWriter.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.powsybl.commons.PowsyblException;
1010
import com.powsybl.commons.exceptions.UncheckedXmlStreamException;
1111
import com.powsybl.commons.xml.XmlUtil;
12+
import com.powsybl.diagram.components.ComponentSize;
1213
import com.powsybl.diagram.util.CssUtil;
1314
import com.powsybl.nad.library.NadComponentLibrary;
1415
import com.powsybl.nad.model.*;
@@ -218,23 +219,42 @@ private void insertSvgComponent(Injection injection, XMLStreamWriter writer) thr
218219
writer.writeStartElement(GROUP_ELEMENT_NAME);
219220
writer.writeAttribute(TRANSFORM_ATTRIBUTE, getTranslateString(injection.getIconOrigin(svgParameters.getInjectionCircleRadius())));
220221

221-
Result result = new SAXResult(new SvgContentHandlerToXMLStreamWriter(writer));
222222
String componentType = injection.getComponentType();
223+
writeSvgComponent(writer, componentType, "Cannot insert SVG for injection of type " + injection.getType());
224+
}
225+
226+
private void drawComponentOnBranchEdgeMiddle(XMLStreamWriter writer, String componentType) throws XMLStreamException {
227+
writer.writeStartElement(GROUP_ELEMENT_NAME);
228+
ComponentSize componentSize = componentLibrary.getComponentsSize().getOrDefault(componentType, null);
229+
230+
if (componentSize == null) {
231+
throw new PowsyblException("Cannot find size for component of type " + componentType);
232+
}
233+
Point trans = new Point(-componentSize.width() / 2, -componentSize.height() / 2);
234+
writer.writeAttribute(TRANSFORM_ATTRIBUTE, getTranslateString(trans));
235+
236+
writeSvgComponent(writer, componentType, "Cannot insert SVG component of type " + componentType + " on branch edge middle");
237+
}
238+
239+
private void writeSvgComponent(XMLStreamWriter writer, String componentType, String errorMessage) throws XMLStreamException {
240+
Result result = new SAXResult(new SvgContentHandlerToXMLStreamWriter(writer));
223241
writeStyleClasses(writer, componentLibrary.getComponentStyleClass(componentType).map(List::of).orElse(List.of()));
224242

225243
try {
226244
Transformer transformer = componentLibrary.getSvgTransformer();
227245
Map<String, List<Element>> subComponents = componentLibrary.getSvgElements(componentType);
228-
for (Map.Entry<String, List<Element>> scEntry : subComponents.entrySet()) {
229-
List<String> edgeStyleClasses = componentLibrary.getSubComponentStyleClass(componentType, scEntry.getKey())
246+
if (subComponents != null) {
247+
for (Map.Entry<String, List<Element>> scEntry : subComponents.entrySet()) {
248+
List<String> edgeStyleClasses = componentLibrary.getSubComponentStyleClass(componentType, scEntry.getKey())
230249
.map(List::of).orElse(List.of());
231-
writeStyleClasses(writer, edgeStyleClasses);
232-
for (Element element : scEntry.getValue()) {
233-
transformer.transform(new DOMSource(element), result);
250+
writeStyleClasses(writer, edgeStyleClasses);
251+
for (Element element : scEntry.getValue()) {
252+
transformer.transform(new DOMSource(element), result);
253+
}
234254
}
235255
}
236256
} catch (TransformerException e) {
237-
throw new PowsyblException("Cannot insert SVG for injection of type " + injection.getType(), e);
257+
throw new PowsyblException(errorMessage, e);
238258
}
239259
writer.writeEndElement();
240260
}
@@ -590,7 +610,7 @@ private <E> void drawEdgeInfoOrLabel(XMLStreamWriter writer,
590610
if (checkIfEdgeInfoIsEmpty(edgeInfo)) {
591611
return;
592612
}
593-
if (edgeInfo.getDirection().isPresent() || edgeInfo.getLabelB().isPresent() && edgeInfo.getLabelA().isPresent()) {
613+
if (edgeInfo.getDirection().isPresent() || edgeInfo.getComponentType().isPresent() || edgeInfo.getLabelB().isPresent() && edgeInfo.getLabelA().isPresent()) {
594614
drawEdgeInfo(writer, svgEdgeInfo, point, edgeAngle);
595615
} else {
596616
String label = edgeInfo.getLabelB().orElse(edgeInfo.getLabelA().orElse(null));
@@ -655,7 +675,13 @@ private void drawEdgeInfo(XMLStreamWriter writer, SvgEdgeInfo svgEdgeInfo, Point
655675
writer.writeStartElement(GROUP_ELEMENT_NAME);
656676
writer.writeAttribute(ID_ATTRIBUTE, svgEdgeInfo.svgId());
657677
writer.writeAttribute(TRANSFORM_ATTRIBUTE, getTranslateString(infoCenter));
658-
drawArrow(writer, edgeInfo, edgeAngle);
678+
679+
Optional<String> componentType = edgeInfo.getComponentType();
680+
if (componentType.isPresent()) {
681+
this.drawComponentOnBranchEdgeMiddle(writer, componentType.get());
682+
} else {
683+
drawArrow(writer, edgeInfo, edgeAngle);
684+
}
659685
Optional<String> label2 = edgeInfo.getLabelB();
660686
if (label2.isPresent()) {
661687
drawLabel(writer, label2.get(), edgeAngle, true, styleProvider.getEdgeInfoStyleClasses(edgeInfo.getInfoTypeB()));

network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/DiagramMetadata.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ private static EdgeInfoMetadata createEdgeInfoMetadata(SvgEdgeInfo svgEdgeInfo)
199199
edgeInfo.getInfoTypeB(),
200200
edgeInfo.getDirection().map(Enum::name).orElse(null),
201201
edgeInfo.getLabelA().orElse(null),
202-
edgeInfo.getLabelB().orElse(null));
202+
edgeInfo.getLabelB().orElse(null),
203+
edgeInfo.getComponentType().orElse(null));
203204
}
204205

205206
private String getPrefixedId(String id) {

network-area-diagram/src/main/java/com/powsybl/nad/svg/metadata/EdgeInfoMetadata.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
package com.powsybl.nad.svg.metadata;
99

10+
import com.fasterxml.jackson.annotation.JsonCreator;
1011
import com.fasterxml.jackson.annotation.JsonInclude;
1112
import com.fasterxml.jackson.annotation.JsonProperty;
1213

@@ -21,19 +22,23 @@ public class EdgeInfoMetadata {
2122
private final String direction;
2223
private final String labelA;
2324
private final String labelB;
25+
private final String componentType;
2426

27+
@JsonCreator
2528
public EdgeInfoMetadata(@JsonProperty("svgId") String svgId,
2629
@JsonProperty("infoTypeA") String infoTypeA,
2730
@JsonProperty("infoTypeB") String infoTypeB,
2831
@JsonProperty("direction") String direction,
2932
@JsonProperty("labelA") String labelA,
30-
@JsonProperty("labelB") String labelB) {
33+
@JsonProperty("labelB") String labelB,
34+
@JsonProperty("componentType") String componentType) {
3135
this.svgId = svgId;
3236
this.infoTypeA = infoTypeA;
3337
this.infoTypeB = infoTypeB;
3438
this.direction = direction;
3539
this.labelA = labelA;
3640
this.labelB = labelB;
41+
this.componentType = componentType;
3742
}
3843

3944
@JsonProperty("svgId")
@@ -65,4 +70,9 @@ public String getLabelA() {
6570
public String getLabelB() {
6671
return labelB;
6772
}
73+
74+
@JsonProperty("componentType")
75+
public String getComponentType() {
76+
return componentType;
77+
}
6878
}

network-area-diagram/src/main/resources/DefaultLibrary/components.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,34 @@
8383
],
8484
"styleClass": "nad-svc"
8585
},
86+
{
87+
"type": "LOCK",
88+
"size": {
89+
"width": 50.0,
90+
"height": 50.0
91+
},
92+
"subComponents": [
93+
{
94+
"name": "LOCK",
95+
"fileName": "lock.svg"
96+
}
97+
],
98+
"styleClass": "nad-lock"
99+
},
100+
{
101+
"type": "FLASH",
102+
"size": {
103+
"width": 50.0,
104+
"height": 50.0
105+
},
106+
"subComponents": [
107+
{
108+
"name": "FLASH",
109+
"fileName": "flash.svg"
110+
}
111+
],
112+
"styleClass": "nad-flash"
113+
},
86114
{
87115
"type": "UNKNOWN_COMPONENT",
88116
"size": {
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)