Skip to content

Commit

Permalink
adds a get_network_area_diagram_svg_and_metadata to pypowsybl's bindi…
Browse files Browse the repository at this point in the history
…ngs; fills the metadata attribute in the get_network_area_diagram's output Svg (python side)

Signed-off-by: Christian Biasuzzi <christian.biasuzzi@soft.it>
  • Loading branch information
CBiasuzzi committed Oct 28, 2024
1 parent 6923825 commit f38a42e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,14 @@ std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vecto
return toString(PowsyblCaller::get()->callJava<char*>(::getNetworkAreaDiagramSvg, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get()));
}

std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters) {
auto c_parameters = parameters.to_c_struct();
ToCharPtrPtr voltageLevelIdPtr(voltageLevelIds);
auto svgAndMetadataArrayPtr = PowsyblCaller::get()->callJava<array*>(::getNetworkAreaDiagramSvgAndMetadata, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth, highNominalVoltageBound, lowNominalVoltageBound, c_parameters.get());
ToStringVector svgAndMetadata(svgAndMetadataArrayPtr);
return svgAndMetadata.get();
}

std::vector<std::string> getNetworkAreaDiagramDisplayedVoltageLevels(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth) {
ToCharPtrPtr voltageLevelIdPtr(voltageLevelIds);
auto displayedVoltageLevelIdsArrayPtr = PowsyblCaller::get()->callJava<array*>(::getNetworkAreaDiagramDisplayedVoltageLevels, network, voltageLevelIdPtr.get(), voltageLevelIds.size(), depth);
Expand Down
2 changes: 2 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ void writeNetworkAreaDiagramSvg(const JavaHandle& network, const std::string& sv

std::string getNetworkAreaDiagramSvg(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters);

std::vector<std::string> getNetworkAreaDiagramSvgAndMetadata(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth, double highNominalVoltageBound, double lowNominalVoltageBound, const NadParameters& parameters);

std::vector<std::string> getNetworkAreaDiagramDisplayedVoltageLevels(const JavaHandle& network, const std::vector<std::string>& voltageLevelIds, int depth);

JavaHandle createSecurityAnalysis();
Expand Down
3 changes: 3 additions & 0 deletions cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ PYBIND11_MODULE(_pypowsybl, m) {

m.def("get_network_area_diagram_svg", &pypowsybl::getNetworkAreaDiagramSvg, "Get network area diagram SVG as a string",
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"));

m.def("get_network_area_diagram_svg_and_metadata", &pypowsybl::getNetworkAreaDiagramSvgAndMetadata, "Get network area diagram SVG and its metadata as a list of strings",
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"), py::arg("high_nominal_voltage_bound"), py::arg("low_nominal_voltage_bound"), py::arg("nad_parameters"));

m.def("get_network_area_diagram_displayed_voltage_levels", &pypowsybl::getNetworkAreaDiagramDisplayedVoltageLevels, "Get network area diagram displayed voltage level",
py::arg("network"), py::arg("voltage_level_ids"), py::arg("depth"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,19 @@ public static CCharPointer getNetworkAreaDiagramSvg(IsolateThread thread, Object
});
}

@CEntryPoint(name = "getNetworkAreaDiagramSvgAndMetadata")
public static ArrayPointer<CCharPointerPointer> getNetworkAreaDiagramSvgAndMetadata(IsolateThread thread, ObjectHandle networkHandle, CCharPointerPointer voltageLevelIdsPointer,
int voltageLevelIdCount, int depth, double highNominalVoltageBound,
double lowNominalVoltageBound, NadParametersPointer nadParametersPointer, ExceptionHandlerPointer exceptionHandlerPtr) {
return doCatch(exceptionHandlerPtr, () -> {
Network network = ObjectHandles.getGlobal().get(networkHandle);
List<String> voltageLevelIds = toStringList(voltageLevelIdsPointer, voltageLevelIdCount);
NadParameters nadParameters = convertNadParameters(nadParametersPointer, network);
List<String> svgAndMeta = NetworkAreaDiagramUtil.getSvgAndMetadata(network, voltageLevelIds, depth, highNominalVoltageBound, lowNominalVoltageBound, nadParameters);
return createCharPtrArray(svgAndMeta);
});
}

@CEntryPoint(name = "getNetworkAreaDiagramDisplayedVoltageLevels")
public static PyPowsyblApiHeader.ArrayPointer<CCharPointerPointer> getNetworkAreaDiagramDisplayedVoltageLevels(IsolateThread thread, ObjectHandle networkHandle, CCharPointerPointer voltageLevelIdsPointer,
int voltageLevelIdCount, int depth, ExceptionHandlerPointer exceptionHandlerPtr) {
Expand Down
1 change: 1 addition & 0 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ def get_security_analysis_provider_parameters_names(provider: str) -> List[str]:
def get_sensitivity_analysis_provider_parameters_names(provider: str) -> List[str]: ...
def get_limit_violations(result: JavaHandle) -> SeriesArray: ...
def get_network_area_diagram_svg(network: JavaHandle, voltage_level_ids: Union[str, List[str]], depth: int, high_nominal_voltage_bound: float, low_nominal_voltage_bound: float, nad_parameters: NadParameters) -> str: ...
def get_network_area_diagram_svg_and_metadata(network: JavaHandle, voltage_level_ids: Union[str, List[str]], depth: int, high_nominal_voltage_bound: float, low_nominal_voltage_bound: float, nad_parameters: NadParameters) -> List[str]: ...
def get_network_area_diagram_displayed_voltage_levels(network: JavaHandle, voltage_level_ids: Union[str, List[str]], depth: int) -> List[str]: ...
def get_network_elements_ids(network: JavaHandle, element_type: ElementType, nominal_voltages: List[float], countries: List[str], main_connected_component: bool, main_synchronous_component: bool, not_connected_to_same_bus_at_both_sides: bool) -> List[str]: ...
def get_network_export_formats() -> List[str]: ...
Expand Down
6 changes: 4 additions & 2 deletions pypowsybl/network/impl/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ def get_network_area_diagram(self, voltage_level_ids: Union[str, List[str]] = No
if isinstance(voltage_level_ids, str):
voltage_level_ids = [voltage_level_ids]
nad_p = nad_parameters._to_c_parameters() if nad_parameters is not None else _pp.NadParameters() # pylint: disable=protected-access
return Svg(_pp.get_network_area_diagram_svg(self._handle, voltage_level_ids, depth,
svg_and_metadata: List[str] = _pp.get_network_area_diagram_svg_and_metadata(self._handle, voltage_level_ids, depth,
high_nominal_voltage_bound, low_nominal_voltage_bound,
nad_p))
nad_p)
return Svg(svg_and_metadata[0], svg_and_metadata[1])


def get_network_area_diagram_displayed_voltage_levels(self, voltage_level_ids: Union[str, List[str]],
depth: int = 0) -> List[str]:
Expand Down

0 comments on commit f38a42e

Please sign in to comment.