Skip to content

Commit

Permalink
add more parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt committed Nov 22, 2023
1 parent 8ac84ef commit 6a9b0e3
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cpp/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ PYBIND11_MODULE(_pypowsybl, m) {
.def(py::init(&pypowsybl::createNadParameters))
.def_readwrite("edge_name_displayed", &pypowsybl::NadParameters::edge_name_displayed)
.def_readwrite("edge_info_along_edge", &pypowsybl::NadParameters::edge_info_along_edge)
.def_readwrite("power_value_precision", &pypowsybl::NadParameters::power_value_precision)
.def_readwrite("current_value_precision", &pypowsybl::NadParameters::current_value_precision)
.def_readwrite("angle_value_precision", &pypowsybl::NadParameters::angle_value_precision)
.def_readwrite("voltage_value_precision", &pypowsybl::NadParameters::voltage_value_precision)
.def_readwrite("id_displayed", &pypowsybl::NadParameters::id_displayed);

m.def("write_single_line_diagram_svg", &pypowsybl::writeSingleLineDiagramSvg, "Write single line diagram SVG",
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/pypowsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ typedef struct nad_parameters_struct {
unsigned char edge_name_displayed;
unsigned char edge_info_along_edge;
unsigned char id_displayed;
int power_value_precision;
int current_value_precision;
int angle_value_precision;
int voltage_value_precision;
} nad_parameters;

typedef enum {
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/pypowsybl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,10 @@ NadParameters::NadParameters(nad_parameters* src) {
edge_name_displayed = (bool) src->edge_name_displayed;
edge_info_along_edge = (bool) src->edge_info_along_edge;
id_displayed = (bool) src->id_displayed;
power_value_precision = src->power_value_precision;
current_value_precision = src->current_value_precision;
angle_value_precision = src->angle_value_precision;
voltage_value_precision = src->voltage_value_precision;
}

void SldParameters::sld_to_c_struct(sld_parameters& res) const {
Expand All @@ -1268,6 +1272,10 @@ void NadParameters::nad_to_c_struct(nad_parameters& res) const {
res.edge_name_displayed = (unsigned char) edge_name_displayed;
res.edge_info_along_edge = (unsigned char) edge_info_along_edge;
res.id_displayed = (unsigned char) id_displayed;
res.power_value_precision = power_value_precision;
res.current_value_precision = current_value_precision;
res.angle_value_precision = angle_value_precision;
res.voltage_value_precision = voltage_value_precision;
}

std::shared_ptr<sld_parameters> SldParameters::to_c_struct() const {
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/pypowsybl.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ class NadParameters {
bool edge_name_displayed;
bool edge_info_along_edge;
bool id_displayed;
int power_value_precision;
int current_value_precision;
int angle_value_precision;
int voltage_value_precision;
};

char* copyStringToCharPtr(const std::string& str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,30 @@ public interface NadParametersPointer extends PointerBase {

@CField("edge_info_along_edge")
boolean isEdgeInfoAlongEdge();

@CField("power_value_precision")
void setPowerValuePrecision(int powerValuePrecision);

@CField("power_value_precision")
int getPowerValuePrecision();

@CField("current_value_precision")
void setCurrentValuePrecision(int currentValuePrecision);

@CField("current_value_precision")
int getCurrentValuePrecision();

@CField("angle_value_precision")
void setAngleValuePrecision(int angleValuePrecision);

@CField("angle_value_precision")
int getAngleValuePrecision();

@CField("voltage_value_precision")
void setVoltageValuePrecision(int voltageValuePrecision);

@CField("voltage_value_precision")
int getVoltageValuePrecision();
}

@CEnum("DynamicMappingType")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ public static NadParameters convertNadParameters(NadParametersPointer nadParamet
nadParameters.getSvgParameters()
.setEdgeNameDisplayed(nadParametersPointer.isEdgeNameDisplayed())
.setEdgeInfoAlongEdge(nadParametersPointer.isEdgeInfoAlongEdge())
.setPowerValuePrecision(nadParametersPointer.getPowerValuePrecision())
.setCurrentValuePrecision(nadParametersPointer.getCurrentValuePrecision())
.setAngleValuePrecision(nadParametersPointer.getAngleValuePrecision())
.setVoltageValuePrecision(nadParametersPointer.getVoltageValuePrecision())
.setIdDisplayed(nadParametersPointer.isIdDisplayed());
return nadParameters;
}
Expand Down
4 changes: 4 additions & 0 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ class NadParameters:
edge_name_displayed: bool
edge_info_along_edge: bool
id_displayed: bool
power_value_precision: int
angle_value_precision: int
current_value_precision: int
voltage_value_precision: int
def __init__(self) -> None: ...

class LimitType:
Expand Down
35 changes: 32 additions & 3 deletions pypowsybl/network/impl/nad_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ class NadParameters:
"""
This class represents nad parameters for a network area diagram svg generation."""

def __init__(self, edge_name_displayed: bool = True, id_displayed: bool = False,
edge_info_along_edge: bool = True):
def __init__(self, edge_name_displayed: bool = False, id_displayed: bool = False,
edge_info_along_edge: bool = True, power_value_precision: int = 0, angle_value_precision: int = 1,
current_value_precision: int = 0, voltage_value_precision: int = 1):
self._edge_name_displayed = edge_name_displayed
self._edge_info_along_edge = edge_info_along_edge
self._id_displayed = id_displayed
self._power_value_precision = power_value_precision
self._angle_value_precision = angle_value_precision
self._current_value_precision = current_value_precision
self._voltage_value_precision = voltage_value_precision

@property
def edge_name_displayed(self) -> bool:
Expand All @@ -31,9 +36,33 @@ def id_displayed(self) -> bool:
"""id_displayed"""
return self._id_displayed

@property
def power_value_precision(self) -> int:
"""power_value_precision"""
return self._power_value_precision

@property
def angle_value_precision(self) -> int:
"""angle_value_precision"""
return self._angle_value_precision

@property
def current_value_precision(self) -> int:
"""current_value_precision"""
return self._current_value_precision

@property
def voltage_value_precision(self) -> int:
"""voltage_value_precision"""
return self._voltage_value_precision

def _to_c_parameters(self) -> _pp.NadParameters:
c_parameters = _pp.NadParameters()
c_parameters.edge_name_displayed = self._edge_name_displayed
c_parameters.edge_info_along_edge = self._edge_info_along_edge
c_parameters.id_displayed = self._id_displayed
return c_parameters
c_parameters.power_value_precision = self._power_value_precision
c_parameters.angle_value_precision = self._angle_value_precision
c_parameters.current_value_precision = self._current_value_precision
c_parameters.voltage_value_precision = self._voltage_value_precision
return c_parameters
17 changes: 14 additions & 3 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,14 @@ def test_sld_nad():
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))
sld = n.get_network_area_diagram('VL6', nad_parameters=NadParameters(edge_name_displayed=True,
id_displayed=True,
edge_info_along_edge=False,
power_value_precision=1,
angle_value_precision=0,
current_value_precision=1,
voltage_value_precision=0
))
assert re.search('.*<svg.*', sld.svg)
with tempfile.TemporaryDirectory() as tmp_dir_name:
test_svg = tmp_dir_name + "test.svg"
Expand All @@ -862,8 +869,12 @@ def test_sld_nad():
n.write_network_area_diagram_svg(test_svg, low_nominal_voltage_bound=10, depth=10)
n.write_network_area_diagram_svg(test_svg, high_nominal_voltage_bound=50, depth=10)
n.write_network_area_diagram(test_svg, nad_parameters=NadParameters(edge_name_displayed=True,
id_displayed=False,
edge_info_along_edge=False))
id_displayed=True,
edge_info_along_edge=False,
power_value_precision=1,
angle_value_precision=0,
current_value_precision=1,
voltage_value_precision=0))


def test_nad_displayed_voltage_levels():
Expand Down

0 comments on commit 6a9b0e3

Please sign in to comment.