From e1080db788a6ce974d488bdc7df499d49bd89166 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 19 Nov 2024 15:52:22 +0100 Subject: [PATCH] Get import supported extensions (#889) Signed-off-by: Geoffroy Jamgotchian --- cpp/powsybl-cpp/powsybl-cpp.cpp | 6 ++++++ cpp/powsybl-cpp/powsybl-cpp.h | 2 ++ cpp/pypowsybl-cpp/bindings.cpp | 1 + .../com/powsybl/python/network/NetworkCFunctions.java | 5 +++++ pypowsybl/_pypowsybl.pyi | 1 + pypowsybl/network/__init__.py | 1 + pypowsybl/network/impl/util.py | 10 ++++++++++ tests/test_network.py | 5 +++++ 8 files changed, 31 insertions(+) diff --git a/cpp/powsybl-cpp/powsybl-cpp.cpp b/cpp/powsybl-cpp/powsybl-cpp.cpp index 7487549816..78a0b870ac 100644 --- a/cpp/powsybl-cpp/powsybl-cpp.cpp +++ b/cpp/powsybl-cpp/powsybl-cpp.cpp @@ -491,6 +491,12 @@ std::vector getNetworkImportPostProcessors() { return postProcessors.get(); } +std::vector getNetworkImportSupportedExtensions() { + auto supportedExtensionsArrayPtr = PowsyblCaller::get()->callJava(::getNetworkImportSupportedExtensions); + ToStringVector supportedExtensions(supportedExtensionsArrayPtr); + return supportedExtensions.get(); +} + std::vector getLoadFlowProviderNames() { auto formatsArrayPtr = PowsyblCaller::get()->callJava(::getLoadFlowProviderNames); ToStringVector formats(formatsArrayPtr); diff --git a/cpp/powsybl-cpp/powsybl-cpp.h b/cpp/powsybl-cpp/powsybl-cpp.h index 068aabe95d..fa753697f8 100644 --- a/cpp/powsybl-cpp/powsybl-cpp.h +++ b/cpp/powsybl-cpp/powsybl-cpp.h @@ -519,6 +519,8 @@ std::vector getNetworkElementsIds(const JavaHandle& network, elemen std::vector getNetworkImportFormats(); +std::vector getNetworkImportSupportedExtensions(); + std::vector getNetworkExportFormats(); std::vector getNetworkImportPostProcessors(); diff --git a/cpp/pypowsybl-cpp/bindings.cpp b/cpp/pypowsybl-cpp/bindings.cpp index 9e97f544f8..7f1b99715b 100644 --- a/cpp/pypowsybl-cpp/bindings.cpp +++ b/cpp/pypowsybl-cpp/bindings.cpp @@ -371,6 +371,7 @@ PYBIND11_MODULE(_pypowsybl, m) { py::arg("not_connected_to_same_bus_at_both_sides")); m.def("get_network_import_formats", &pypowsybl::getNetworkImportFormats, "Get supported import formats"); + m.def("get_network_import_supported_extensions", &pypowsybl::getNetworkImportSupportedExtensions, "Get supported import extensions"); m.def("get_network_export_formats", &pypowsybl::getNetworkExportFormats, "Get supported export formats"); m.def("get_network_import_post_processors", &pypowsybl::getNetworkImportPostProcessors, "Get supported import post processors"); 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 c4861e0f6d..0bd9547035 100644 --- a/java/src/main/java/com/powsybl/python/network/NetworkCFunctions.java +++ b/java/src/main/java/com/powsybl/python/network/NetworkCFunctions.java @@ -95,6 +95,11 @@ public static ArrayPointer getNetworkImportFormats(IsolateT return doCatch(exceptionHandlerPtr, () -> createCharPtrArray(Importer.getFormats().stream().sorted().toList())); } + @CEntryPoint(name = "getNetworkImportSupportedExtensions") + public static ArrayPointer getNetworkImportSupportedExtensions(IsolateThread thread, ExceptionHandlerPointer exceptionHandlerPtr) { + return doCatch(exceptionHandlerPtr, () -> createCharPtrArray(Importer.list().stream().flatMap(l -> l.getSupportedExtensions().stream()).distinct().sorted().toList())); + } + @CEntryPoint(name = "getNetworkExportFormats") public static ArrayPointer getNetworkExportFormats(IsolateThread thread, ExceptionHandlerPointer exceptionHandlerPtr) { return doCatch(exceptionHandlerPtr, () -> createCharPtrArray(Exporter.getFormats().stream().sorted().toList())); diff --git a/pypowsybl/_pypowsybl.pyi b/pypowsybl/_pypowsybl.pyi index 58c7aa42ea..421ee6feb6 100644 --- a/pypowsybl/_pypowsybl.pyi +++ b/pypowsybl/_pypowsybl.pyi @@ -786,6 +786,7 @@ def get_network_area_diagram_displayed_voltage_levels(network: JavaHandle, volta 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]: ... def get_network_import_formats() -> List[str]: ... +def get_network_import_supported_extensions() -> List[str]: ... def get_network_import_post_processors() -> List[str]: ... def get_loadflow_provider_names() -> List[str]: ... def get_security_analysis_provider_names() -> List[str]: ... diff --git a/pypowsybl/network/__init__.py b/pypowsybl/network/__init__.py index a1a8583234..60c1c27c9f 100644 --- a/pypowsybl/network/__init__.py +++ b/pypowsybl/network/__init__.py @@ -43,6 +43,7 @@ get_extensions_names, get_single_line_diagram_component_library_names, get_import_formats, + get_import_supported_extensions, get_export_formats, get_import_post_processors, get_import_parameters, diff --git a/pypowsybl/network/impl/util.py b/pypowsybl/network/impl/util.py index a33251afe0..ea7b2be2bb 100644 --- a/pypowsybl/network/impl/util.py +++ b/pypowsybl/network/impl/util.py @@ -31,6 +31,16 @@ def get_import_formats() -> List[str]: return _pp.get_network_import_formats() +def get_import_supported_extensions() -> List[str]: + """ + Get list of supported import extensions + + Returns: + the list of supported import extensions + """ + return _pp.get_network_import_supported_extensions() + + def get_export_formats() -> List[str]: """ Get list of supported export formats diff --git a/tests/test_network.py b/tests/test_network.py index 98951b34f7..c24948a97a 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -157,6 +157,11 @@ def test_get_import_format(): assert ['BIIDM', 'CGMES', 'IEEE-CDF', 'JIIDM', 'MATPOWER', 'POWER-FACTORY', 'PSS/E', 'UCTE', 'XIIDM'] == formats +def test_get_import_supported_extensions(): + extensions = pp.network.get_import_supported_extensions() + assert ['RAW', 'RAWX', 'UCT', 'biidm', 'bin', 'dgs', 'iidm', 'jiidm', 'json', 'mat', 'raw', 'rawx', 'txt', 'uct', 'xiidm', 'xml'] == extensions + + def test_get_import_parameters(): parameters = pp.network.get_import_parameters('PSS/E') assert 1 == len(parameters)