Skip to content

Commit

Permalink
Avoid svg components duplication #44
Browse files Browse the repository at this point in the history
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
  • Loading branch information
FranckLecuyer committed Oct 7, 2019
1 parent 867eacf commit fc5829f
Show file tree
Hide file tree
Showing 49 changed files with 4,532 additions and 2,213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class LayoutParameters {
private boolean shiftFeedersPosition = false;

private double scaleShiftFeedersPosition = 1;
private boolean avoidSVGComponentsDuplication = false;

@JsonCreator
public LayoutParameters() {
Expand Down Expand Up @@ -83,7 +84,8 @@ public LayoutParameters(@JsonProperty("translateX") double translateX,
@JsonProperty("showInductorFor3WT") boolean showInductorFor3WT,
@JsonProperty("diagramName") String diagramName,
@JsonProperty("shiftFeedersPosition") boolean shiftFeedersPosition,
@JsonProperty("scaleShiftFeedersPosition") double scaleShiftFeedersPosition) {
@JsonProperty("scaleShiftFeedersPosition") double scaleShiftFeedersPosition,
@JsonProperty("avoidSVGComponentsDuplication") boolean avoidSVGComponentsDuplication) {
this.translateX = translateX;
this.translateY = translateY;
this.initialXBus = initialXBus;
Expand All @@ -107,6 +109,7 @@ public LayoutParameters(@JsonProperty("translateX") double translateX,
this.diagramName = diagramName;
this.shiftFeedersPosition = shiftFeedersPosition;
this.scaleShiftFeedersPosition = scaleShiftFeedersPosition;
this.avoidSVGComponentsDuplication = avoidSVGComponentsDuplication;
}

public LayoutParameters(LayoutParameters other) {
Expand Down Expand Up @@ -134,6 +137,7 @@ public LayoutParameters(LayoutParameters other) {
diagramName = other.diagramName;
shiftFeedersPosition = other.shiftFeedersPosition;
scaleShiftFeedersPosition = other.scaleShiftFeedersPosition;
avoidSVGComponentsDuplication = other.avoidSVGComponentsDuplication;
}

public double getTranslateX() {
Expand Down Expand Up @@ -343,4 +347,12 @@ public LayoutParameters setScaleShiftFeedersPosition(double scaleShiftFeedersPos
return this;
}

public boolean isAvoidSVGComponentsDuplication() {
return avoidSVGComponentsDuplication;
}

public LayoutParameters setAvoidSVGComponentsDuplication(boolean avoidSVGComponentsDuplication) {
this.avoidSVGComponentsDuplication = avoidSVGComponentsDuplication;
return this;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -54,9 +56,9 @@ public Optional<String> getGlobalStyle(Graph graph) {
}

@Override
public Optional<String> getNodeStyle(Node node) {
public Optional<String> getNodeStyle(Node node, boolean avoidSVGComponentsDuplication) {
Objects.requireNonNull(node);
if (node.getType() == Node.NodeType.SWITCH) {
if (node.getType() == Node.NodeType.SWITCH && !avoidSVGComponentsDuplication) {
try {
StringBuilder style = new StringBuilder();
String className = escapeClassName(URLEncoder.encode(node.getId(), StandardCharsets.UTF_8.name()));
Expand All @@ -71,7 +73,7 @@ public Optional<String> getNodeStyle(Node node) {
throw new UncheckedIOException(e);
}
}
if (node instanceof FeederNode) {
if (node instanceof FeederNode && !avoidSVGComponentsDuplication) {
try {
StringBuilder style = new StringBuilder();
style.append(ARROW1).append(escapeClassName(URLEncoder.encode(node.getId(), StandardCharsets.UTF_8.name())))
Expand Down Expand Up @@ -126,4 +128,13 @@ public Optional<String> getNode2WTStyle(Feeder2WTNode node, TwoWindingsTransform
public Optional<String> getColor(VoltageLevel vl) {
return Optional.empty();
}

@Override
public Map<String, String> getAttributesArrow(int num) {
Map<String, String> ret = new HashMap<>();
ret.put("stroke", num == 1 ? "black" : "blue");
ret.put("fill", num == 1 ? "black" : "blue");
ret.put("fill-opacity", "1");
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/
package com.powsybl.substationdiagram.svg;

import java.io.Writer;
import java.nio.file.Path;

import com.powsybl.substationdiagram.layout.LayoutParameters;
import com.powsybl.substationdiagram.library.ComponentLibrary;
import com.powsybl.substationdiagram.model.Graph;
import com.powsybl.substationdiagram.model.SubstationGraph;

import java.io.Writer;
import java.nio.file.Path;

/**
* @author Gilles Brada <gilles.brada at rte-france.com>
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.powsybl.substationdiagram.svg;

import java.util.Map;
import java.util.Optional;

import com.powsybl.iidm.network.ThreeWindingsTransformer;
Expand All @@ -25,7 +26,7 @@ public interface SubstationDiagramStyleProvider {

Optional<String> getGlobalStyle(Graph graph);

Optional<String> getNodeStyle(Node node);
Optional<String> getNodeStyle(Node node, boolean avoidSVGComponentsDuplication);

String getIdWireStyle(Edge edge);

Expand All @@ -36,4 +37,6 @@ public interface SubstationDiagramStyleProvider {
Optional<String> getNode2WTStyle(Feeder2WTNode node, TwoWindingsTransformer.Side side);

Optional<String> getColor(VoltageLevel vl);

Map<String, String> getAttributesArrow(int num);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public Optional<String> getGlobalStyle(Graph graph) {
}

@Override
public Optional<String> getNodeStyle(Node node) {
Optional<String> defaultStyle = super.getNodeStyle(node);
public Optional<String> getNodeStyle(Node node, boolean avoidSVGComponentsDuplication) {
Optional<String> defaultStyle = super.getNodeStyle(node, avoidSVGComponentsDuplication);

String color = getColor(node.getGraph().getVoltageLevel()).orElse(DEFAULT_COLOR);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public Optional<String> getGlobalStyle(Graph graph) {
}

@Override
public Optional<String> getNodeStyle(Node node) {
public Optional<String> getNodeStyle(Node node, boolean avoidSVGComponentsDuplication) {

Optional<String> defaultStyle = super.getNodeStyle(node);
Optional<String> defaultStyle = super.getNodeStyle(node, avoidSVGComponentsDuplication);
if (node.getType() == NodeType.SWITCH || node.getComponentType().equals(TWO_WINDINGS_TRANSFORMER) || node.getComponentType().equals(THREE_WINDINGS_TRANSFORMER) || node.getComponentType().equals(PHASE_SHIFT_TRANSFORMER)) {
return defaultStyle;
}
Expand Down
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 fc5829f

Please sign in to comment.