Skip to content

Commit

Permalink
add tooltip enabled parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt committed Dec 6, 2023
1 parent bc3ad00 commit afb5693
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 22 deletions.
1 change: 1 addition & 0 deletions cpp/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ PYBIND11_MODULE(_pypowsybl, m) {
.def_readwrite("center_name", &pypowsybl::SldParameters::center_name)
.def_readwrite("diagonal_label", &pypowsybl::SldParameters::diagonal_label)
.def_readwrite("nodes_infos", &pypowsybl::SldParameters::nodes_infos)
.def_readwrite("tool_tip_enabled", &pypowsybl::SldParameters::tool_tip_enabled)
.def_readwrite("topological_coloring", &pypowsybl::SldParameters::topological_coloring)
.def_readwrite("component_library", &pypowsybl::SldParameters::component_library);

Expand Down
1 change: 1 addition & 0 deletions cpp/src/pypowsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ typedef struct sld_parameters_struct {
unsigned char center_name;
unsigned char diagonal_label;
unsigned char nodes_infos;
unsigned char tool_tip_enabled;
unsigned char topological_coloring;
char* component_library;
} sld_parameters;
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/pypowsybl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ SldParameters::SldParameters(sld_parameters* src) {
center_name = (bool) src->center_name;
diagonal_label = (bool) src->diagonal_label;
nodes_infos = (bool) src->nodes_infos;
tool_tip_enabled = (bool) src->tool_tip_enabled;
topological_coloring = (bool) src->topological_coloring;
component_library = toString(src->component_library);
}
Expand All @@ -1258,6 +1259,7 @@ void SldParameters::sld_to_c_struct(sld_parameters& res) const {
res.center_name = (unsigned char) center_name;
res.diagonal_label = (unsigned char) diagonal_label;
res.nodes_infos = (unsigned char) nodes_infos;
res.tool_tip_enabled = (unsigned char) tool_tip_enabled;
res.topological_coloring = (unsigned char) topological_coloring;
res.component_library = copyStringToCharPtr(component_library);
}
Expand Down
1 change: 1 addition & 0 deletions cpp/src/pypowsybl.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class SldParameters {
bool center_name;
bool diagonal_label;
bool nodes_infos;
bool tool_tip_enabled;
bool topological_coloring;
std::string component_library;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,12 @@ public interface SldParametersPointer extends PointerBase {
@CField("nodes_infos")
void setAddNodesInfos(boolean addNodeInfos);

@CField("tool_tip_enabled")
void setToolTipEnabled(boolean toolTipEnabled);

@CField("tool_tip_enabled")
boolean getToolTipEnabled();

@CField("topological_coloring")
boolean isTopologicalColoring();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ public static void copyToCSldParameters(SldParameters parameters, SldParametersP
cParameters.setDiagonalLabel(parameters.getSvgParameters().isLabelDiagonal());
cParameters.setTopologicalColoring(parameters.getStyleProviderFactory() instanceof DefaultStyleProviderFactory);
cParameters.setAddNodesInfos(parameters.getSvgParameters().isAddNodesInfos());
cParameters.setToolTipEnabled(parameters.getSvgParameters().isTooltipEnabled());
cParameters.setComponentLibrary(CTypeUtil.toCharPtr(parameters.getComponentLibrary().getName()));
}

Expand Down Expand Up @@ -918,13 +919,15 @@ public static void freeNadParameters(IsolateThread thread, NadParametersPointer
public static SldParameters convertSldParameters(SldParametersPointer sldParametersPtr) {
String componentLibraryName = CTypeUtil.toString(sldParametersPtr.getComponentLibrary());
SldParameters sldParameters = SingleLineDiagramUtil.createSldParameters()
.setStyleProviderFactory(sldParametersPtr.isTopologicalColoring() ? new DefaultStyleProviderFactory() : new NominalVoltageStyleProviderFactory())
.setStyleProviderFactory(sldParametersPtr.isTopologicalColoring() ? new DefaultStyleProviderFactory() :
new NominalVoltageStyleProviderFactory())
.setComponentLibrary(ComponentLibrary.find(componentLibraryName).orElseGet(ConvergenceComponentLibrary::new));
sldParameters.getSvgParameters()
.setUseName(sldParametersPtr.isUseName())
.setLabelCentered(sldParametersPtr.isCenterName())
.setLabelDiagonal(sldParametersPtr.isDiagonalLabel())
.setAddNodesInfos(sldParametersPtr.isAddNodesInfos());
.setAddNodesInfos(sldParametersPtr.isAddNodesInfos())
.setTooltipEnabled(sldParametersPtr.getToolTipEnabled());
return sldParameters;
}

Expand Down
1 change: 1 addition & 0 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class SldParameters:
center_name: bool
diagonal_label: bool
nodes_infos: bool
tool_tip_enabled: bool
topological_coloring: bool
component_library: str
def __init__(self) -> None: ...
Expand Down
10 changes: 9 additions & 1 deletion pypowsybl/network/impl/sld_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class SldParameters:
This class represents sld parameters for a single line diagram svg generation."""

def __init__(self, use_name: bool = False, center_name: bool = False, diagonal_label: bool = False,
nodes_infos: bool = False, topological_coloring: bool = True, component_library: str = 'Convergence'):
nodes_infos: bool = False, tool_tip_enabled: bool = False, topological_coloring: bool = True,
component_library: str = 'Convergence'):
self._use_name = use_name
self._center_name = center_name
self._diagonal_label = diagonal_label
self._nodes_infos = nodes_infos
self._tool_tip_enabled = tool_tip_enabled
self._topological_coloring = topological_coloring
self._component_library = component_library

Expand All @@ -40,6 +42,11 @@ def nodes_infos(self) -> bool:
"""When True, add infos about voltage and angle."""
return self._nodes_infos

@property
def tool_tip_enabled(self) -> bool:
"""when True display tooltip"""
return self._tool_tip_enabled

@property
def topological_coloring(self) -> bool:
"""When False, coloring is based only on nominal voltage."""
Expand All @@ -57,5 +64,6 @@ def _to_c_parameters(self) -> _pp.SldParameters:
c_parameters.diagonal_label = self._diagonal_label
c_parameters.topological_coloring = self._topological_coloring
c_parameters.nodes_infos = self._nodes_infos
c_parameters.tool_tip_enabled = self._tool_tip_enabled
c_parameters.component_library = self._component_library
return c_parameters
39 changes: 20 additions & 19 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,11 +813,12 @@ def test_sld_svg():
assert re.search('.*<svg.*', sld.svg)
assert len(sld.metadata) > 0
sld1 = n.get_single_line_diagram('S1VL1', SldParameters(use_name=True, center_name=True, diagonal_label=True,
topological_coloring=False))
topological_coloring=False, tool_tip_enabled=True))
assert re.search('.*<svg.*', sld1.svg)
assert len(sld1.metadata) > 0
sld2 = n.get_single_line_diagram('S1VL1', SldParameters(use_name=True, center_name=True, diagonal_label=True,
nodes_infos=True, topological_coloring=True))
nodes_infos=True, topological_coloring=True,
tool_tip_enabled=True))
assert re.search('.*<svg.*', sld2.svg)
assert len(sld2.metadata) > 0

Expand All @@ -834,24 +835,24 @@ def test_sld_svg_backward_compatibility():
assert len(sld1.metadata) > 0


def test_sld_nad():
def test_nad():
n = pp.network.create_ieee14()
sld = n.get_network_area_diagram()
assert re.search('.*<svg.*', sld.svg)
sld = n.get_network_area_diagram(voltage_level_ids=None)
assert re.search('.*<svg.*', sld.svg)
sld = n.get_network_area_diagram('VL1')
assert re.search('.*<svg.*', sld.svg)
sld = n.get_network_area_diagram(['VL1', 'VL2'])
assert re.search('.*<svg.*', sld.svg)
sld = n.get_network_area_diagram('VL6', high_nominal_voltage_bound=50, low_nominal_voltage_bound=10, depth=10)
assert re.search('.*<svg.*', sld.svg)
sld = n.get_network_area_diagram('VL6', low_nominal_voltage_bound=10, depth=10)
assert re.search('.*<svg.*', sld.svg)
sld = n.get_network_area_diagram('VL6', high_nominal_voltage_bound=50, depth=10)
assert re.search('.*<svg.*', sld.svg)
sld = n.get_network_area_diagram('VL6', nad_parameters=NadParameters(edge_name_displayed=True))
assert re.search('.*<svg.*', sld.svg)
nad = n.get_network_area_diagram()
assert re.search('.*<svg.*', nad.svg)
nad = n.get_network_area_diagram(voltage_level_ids=None)
assert re.search('.*<svg.*', nad.svg)
nad = n.get_network_area_diagram('VL1')
assert re.search('.*<svg.*', nad.svg)
nad = n.get_network_area_diagram(['VL1', 'VL2'])
assert re.search('.*<svg.*', nad.svg)
nad = n.get_network_area_diagram('VL6', high_nominal_voltage_bound=50, low_nominal_voltage_bound=10, depth=10)
assert re.search('.*<svg.*', nad.svg)
nad = n.get_network_area_diagram('VL6', low_nominal_voltage_bound=10, depth=10)
assert re.search('.*<svg.*', nad.svg)
nad = n.get_network_area_diagram('VL6', high_nominal_voltage_bound=50, depth=10)
assert re.search('.*<svg.*', nad.svg)
nad = n.get_network_area_diagram('VL6', nad_parameters=NadParameters(edge_name_displayed=True))
assert re.search('.*<svg.*', nad.svg)
with tempfile.TemporaryDirectory() as tmp_dir_name:
test_svg = tmp_dir_name + "test.svg"
n.write_network_area_diagram_svg(test_svg, None)
Expand Down

0 comments on commit afb5693

Please sign in to comment.