diff --git a/cpp/src/bindings.cpp b/cpp/src/bindings.cpp index 4f59c23d8a..bbd8e18915 100644 --- a/cpp/src/bindings.cpp +++ b/cpp/src/bindings.cpp @@ -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", diff --git a/cpp/src/pypowsybl-api.h b/cpp/src/pypowsybl-api.h index 054ef6d568..2125e9dd32 100644 --- a/cpp/src/pypowsybl-api.h +++ b/cpp/src/pypowsybl-api.h @@ -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 { diff --git a/cpp/src/pypowsybl.cpp b/cpp/src/pypowsybl.cpp index 94afaa9704..9f35f0ba09 100644 --- a/cpp/src/pypowsybl.cpp +++ b/cpp/src/pypowsybl.cpp @@ -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 { @@ -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 SldParameters::to_c_struct() const { diff --git a/cpp/src/pypowsybl.h b/cpp/src/pypowsybl.h index 80b28487af..e0c1a5de49 100644 --- a/cpp/src/pypowsybl.h +++ b/cpp/src/pypowsybl.h @@ -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); diff --git a/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java b/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java index 06e888c465..5f4a8a4d78 100644 --- a/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java +++ b/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java @@ -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") diff --git a/java/src/main/java/com/powsybl/python/network/NetworkCFunctions.java b/java/src/main/java/com/powsybl/python/network/NetworkCFunctions.java index e0dc253de3..c25ce7e42f 100644 --- a/java/src/main/java/com/powsybl/python/network/NetworkCFunctions.java +++ b/java/src/main/java/com/powsybl/python/network/NetworkCFunctions.java @@ -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; } diff --git a/pypowsybl/_pypowsybl.pyi b/pypowsybl/_pypowsybl.pyi index bd5d0f630b..daf5333ea7 100644 --- a/pypowsybl/_pypowsybl.pyi +++ b/pypowsybl/_pypowsybl.pyi @@ -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: diff --git a/pypowsybl/network/impl/nad_parameters.py b/pypowsybl/network/impl/nad_parameters.py index 7e9b9abca1..72ed5a9762 100644 --- a/pypowsybl/network/impl/nad_parameters.py +++ b/pypowsybl/network/impl/nad_parameters.py @@ -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: @@ -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 \ No newline at end of file + 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 diff --git a/pypowsybl/network/impl/network.py b/pypowsybl/network/impl/network.py index 53081afe9c..b1c8e4c1b8 100644 --- a/pypowsybl/network/impl/network.py +++ b/pypowsybl/network/impl/network.py @@ -249,33 +249,12 @@ def get_single_line_diagram(self, container_id: str, parameters: SldParameters = return Svg(svg_and_metadata[0], svg_and_metadata[1]) def write_network_area_diagram_svg(self, svg_file: PathOrStr, voltage_level_ids: Union[str, List[str]] = None, - depth: int = 0, high_nominal_voltage_bound: float = -1, - low_nominal_voltage_bound: float = -1, - edge_name_displayed: bool = False) -> None: - """ - .. deprecated:: 1.1.0 - Use :class:`write_network_area_diagram_svg` with `NadParameters` instead. - - Create a network area diagram in SVG format and write it to a file. - Args: - svg_file: a svg file path - voltage_level_id: the voltage level ID, center of the diagram (None for the full diagram) - depth: the diagram depth around the voltage level - high_nominal_voltage_bound: high bound to filter voltage level according to nominal voltage - low_nominal_voltage_bound: low bound to filter voltage level according to nominal voltage - edge_name_displayed: if true displays the edge's names - """ - nad_p = NadParameters(edge_name_displayed=edge_name_displayed) - self.write_network_area_diagram(svg_file, voltage_level_ids, depth, high_nominal_voltage_bound, - low_nominal_voltage_bound, nad_p) - - def write_network_area_diagram(self, svg_file: PathOrStr, voltage_level_ids: Union[str, List[str]] = None, depth: int = 0, high_nominal_voltage_bound: float = -1, low_nominal_voltage_bound: float = -1, - nad_parameters: NadParameters = None) -> None: + edge_name_displayed: bool = False) -> None: """ .. deprecated:: 1.1.0 - Use :meth:`write_network_area_diagram` with `NadParameters` instead. + Use :class:`write_network_area_diagram_svg` with `NadParameters` instead. Create a network area diagram in SVG format and write it to a file. Args: @@ -288,12 +267,12 @@ def write_network_area_diagram(self, svg_file: PathOrStr, voltage_level_ids: Uni """ nad_p = NadParameters(edge_name_displayed=edge_name_displayed) self.write_network_area_diagram(svg_file, voltage_level_ids, depth, high_nominal_voltage_bound, - low_nominal_voltage_bound, nad_p) + low_nominal_voltage_bound, nad_p) def write_network_area_diagram(self, svg_file: PathOrStr, voltage_level_ids: Union[str, List[str]] = None, - depth: int = 0, high_nominal_voltage_bound: float = -1, - low_nominal_voltage_bound: float = -1, - nad_parameters: NadParameters = None) -> None: + depth: int = 0, high_nominal_voltage_bound: float = -1, + low_nominal_voltage_bound: float = -1, + nad_parameters: NadParameters = None) -> None: """ Create a network area diagram in SVG format and write it to a file. diff --git a/tests/test_network.py b/tests/test_network.py index b8c0443866..744413570f 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -850,7 +850,14 @@ def test_sld_nad(): assert re.search('.*