Skip to content

Commit

Permalink
Merge branch 'main' into nad_get_displayed_voltagelevels_prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneLt authored Oct 17, 2023
2 parents 1136e2d + b744e4f commit 443b218
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 212 deletions.
20 changes: 10 additions & 10 deletions cpp/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,23 +455,23 @@ PYBIND11_MODULE(_pypowsybl, m) {
m.def("run_loadflow_validation", &pypowsybl::runLoadFlowValidation, "Run a load flow validation", py::arg("network"),
py::arg("validation_type"), py::arg("validation_parameters"));

py::class_<pypowsybl::LayoutParameters>(m, "LayoutParameters")
.def(py::init(&pypowsybl::createLayoutParameters))
.def_readwrite("use_name", &pypowsybl::LayoutParameters::use_name)
.def_readwrite("center_name", &pypowsybl::LayoutParameters::center_name)
.def_readwrite("diagonal_label", &pypowsybl::LayoutParameters::diagonal_label)
.def_readwrite("topological_coloring", &pypowsybl::LayoutParameters::topological_coloring)
.def_readwrite("nodes_infos", &pypowsybl::LayoutParameters::nodes_infos)
.def_readwrite("component_library", &pypowsybl::LayoutParameters::component_library);
py::class_<pypowsybl::SldParameters>(m, "SldParameters")
.def(py::init(&pypowsybl::createSldParameters))
.def_readwrite("use_name", &pypowsybl::SldParameters::use_name)
.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("topological_coloring", &pypowsybl::SldParameters::topological_coloring)
.def_readwrite("component_library", &pypowsybl::SldParameters::component_library);

m.def("write_single_line_diagram_svg", &pypowsybl::writeSingleLineDiagramSvg, "Write single line diagram SVG",
py::arg("network"), py::arg("container_id"), py::arg("svg_file"), py::arg("metadata_file"), py::arg("layout_parameters"));
py::arg("network"), py::arg("container_id"), py::arg("svg_file"), py::arg("metadata_file"), py::arg("sld_parameters"));

m.def("get_single_line_diagram_svg", &pypowsybl::getSingleLineDiagramSvg, "Get single line diagram SVG as a string",
py::arg("network"), py::arg("container_id"));

m.def("get_single_line_diagram_svg_and_metadata", &pypowsybl::getSingleLineDiagramSvgAndMetadata, "Get single line diagram SVG and its metadata as a list of strings",
py::arg("network"), py::arg("container_id"), py::arg("layout_parameters"));
py::arg("network"), py::arg("container_id"), py::arg("sld_parameters"));

m.def("get_single_line_diagram_component_library_names", &pypowsybl::getSingleLineDiagramComponentLibraryNames, "Get supported component library providers for single line diagram");

Expand Down
6 changes: 3 additions & 3 deletions cpp/src/pypowsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ typedef struct flow_decomposition_parameters_struct {
int sensitivity_variable_batch_size;
} flow_decomposition_parameters;

typedef struct layout_parameters_struct {
typedef struct sld_parameters_struct {
unsigned char use_name;
unsigned char center_name;
unsigned char diagonal_label;
unsigned char topological_coloring;
unsigned char nodes_infos;
unsigned char topological_coloring;
char* component_library;
} layout_parameters;
} sld_parameters;

typedef enum {
ALPHA_BETA_LOAD = 0,
Expand Down
30 changes: 15 additions & 15 deletions cpp/src/pypowsybl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ SeriesArray* runLoadFlowValidation(const JavaHandle& network, validation_type va
return new SeriesArray(callJava<array*>(::runLoadFlowValidation, network, validationType, c_validation_parameters.get()));
}

void writeSingleLineDiagramSvg(const JavaHandle& network, const std::string& containerId, const std::string& svgFile, const std::string& metadataFile, const LayoutParameters& parameters) {
void writeSingleLineDiagramSvg(const JavaHandle& network, const std::string& containerId, const std::string& svgFile, const std::string& metadataFile, const SldParameters& parameters) {
auto c_parameters = parameters.to_c_struct();
callJava(::writeSingleLineDiagramSvg, network, (char*) containerId.data(), (char*) svgFile.data(), (char*) metadataFile.data(), c_parameters.get());
}
Expand All @@ -766,7 +766,7 @@ std::string getSingleLineDiagramSvg(const JavaHandle& network, const std::string
return toString(callJava<char*>(::getSingleLineDiagramSvg, network, (char*) containerId.data()));
}

std::vector<std::string> getSingleLineDiagramSvgAndMetadata(const JavaHandle& network, const std::string& containerId, const LayoutParameters& parameters) {
std::vector<std::string> getSingleLineDiagramSvgAndMetadata(const JavaHandle& network, const std::string& containerId, const SldParameters& parameters) {
auto c_parameters = parameters.to_c_struct();
auto svgAndMetadataArrayPtr = callJava<array*>(::getSingleLineDiagramSvgAndMetadata, network, (char*) containerId.data(), c_parameters.get());
ToStringVector svgAndMetadata(svgAndMetadataArrayPtr);
Expand Down Expand Up @@ -1239,40 +1239,40 @@ void closePypowsybl() {
pypowsybl::callJava(::closePypowsybl);
}

LayoutParameters::LayoutParameters(layout_parameters* src) {
SldParameters::SldParameters(sld_parameters* src) {
use_name = (bool) src->use_name;
center_name = (bool) src->center_name;
diagonal_label = (bool) src->diagonal_label;
topological_coloring = (bool) src->topological_coloring;
nodes_infos = (bool) src->nodes_infos;
topological_coloring = (bool) src->topological_coloring;
component_library = toString(src->component_library);
}

void LayoutParameters::layout_to_c_struct(layout_parameters& res) const {
void SldParameters::sld_to_c_struct(sld_parameters& res) const {
res.use_name = (unsigned char) use_name;
res.center_name = (unsigned char) center_name;
res.diagonal_label = (unsigned char) diagonal_label;
res.topological_coloring = (unsigned char) topological_coloring;
res.nodes_infos = (unsigned char) nodes_infos;
res.topological_coloring = (unsigned char) topological_coloring;
res.component_library = copyStringToCharPtr(component_library);
}

std::shared_ptr<layout_parameters> LayoutParameters::to_c_struct() const {
layout_parameters* res = new layout_parameters();
layout_to_c_struct(*res);
std::shared_ptr<sld_parameters> SldParameters::to_c_struct() const {
sld_parameters* res = new sld_parameters();
sld_to_c_struct(*res);
//Memory has been allocated here on C side, we need to clean it up on C side (not java side)
return std::shared_ptr<layout_parameters>(res, [](layout_parameters* ptr){
return std::shared_ptr<sld_parameters>(res, [](sld_parameters* ptr){
delete ptr;
});
}

LayoutParameters* createLayoutParameters() {
layout_parameters* parameters_ptr = callJava<layout_parameters*>(::createLayoutParameters);
auto parameters = std::shared_ptr<layout_parameters>(parameters_ptr, [](layout_parameters* ptr){
SldParameters* createSldParameters() {
sld_parameters* parameters_ptr = callJava<sld_parameters*>(::createSldParameters);
auto parameters = std::shared_ptr<sld_parameters>(parameters_ptr, [](sld_parameters* ptr){
//Memory has been allocated on java side, we need to clean it up on java side
callJava(::freeLayoutParameters, ptr);
callJava(::freeSldParameters, ptr);
});
return new LayoutParameters(parameters.get());
return new SldParameters(parameters.get());
}

void removeElementsModification(pypowsybl::JavaHandle network, const std::vector<std::string>& connectableIds, dataframe* dataframe, remove_modification_type removeModificationType, bool throwException, JavaHandle* reporter) {
Expand Down
16 changes: 8 additions & 8 deletions cpp/src/pypowsybl.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,17 @@ class FlowDecompositionParameters {
int sensitivity_variable_batch_size;
};

class LayoutParameters {
class SldParameters {
public:
LayoutParameters(layout_parameters* src);
std::shared_ptr<layout_parameters> to_c_struct() const;
void layout_to_c_struct(layout_parameters& params) const;
SldParameters(sld_parameters* src);
std::shared_ptr<sld_parameters> to_c_struct() const;
void sld_to_c_struct(sld_parameters& params) const;

bool use_name;
bool center_name;
bool diagonal_label;
bool topological_coloring;
bool nodes_infos;
bool topological_coloring;
std::string component_library;
};

Expand Down Expand Up @@ -368,11 +368,11 @@ LoadFlowComponentResultArray* runLoadFlow(const JavaHandle& network, bool dc, co

SeriesArray* runLoadFlowValidation(const JavaHandle& network, validation_type validationType, const LoadFlowValidationParameters& validationParameters);

void writeSingleLineDiagramSvg(const JavaHandle& network, const std::string& containerId, const std::string& svgFile, const std::string& metadataFile, const LayoutParameters& parameters);
void writeSingleLineDiagramSvg(const JavaHandle& network, const std::string& containerId, const std::string& svgFile, const std::string& metadataFile, const SldParameters& parameters);

std::string getSingleLineDiagramSvg(const JavaHandle& network, const std::string& containerId);

std::vector<std::string> getSingleLineDiagramSvgAndMetadata(const JavaHandle& network, const std::string& containerId, const LayoutParameters& parameters);
std::vector<std::string> getSingleLineDiagramSvgAndMetadata(const JavaHandle& network, const std::string& containerId, const SldParameters& parameters);

std::vector<std::string> getSingleLineDiagramComponentLibraryNames();

Expand Down Expand Up @@ -539,7 +539,7 @@ void closePypowsybl();

void removeElementsModification(pypowsybl::JavaHandle network, const std::vector<std::string>& connectableIds, dataframe* dataframe, remove_modification_type removeModificationType, bool throwException, JavaHandle* reporter);

LayoutParameters* createLayoutParameters();
SldParameters* createSldParameters();

//=======dynamic modeling for dynawaltz package==========

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ public interface FlowDecompositionParametersPointer extends PointerBase {
void setSensitivityVariableBatchSize(int sensitivityVariableBatchSize);
}

@CStruct("layout_parameters")
public interface LayoutParametersPointer extends PointerBase {
@CStruct("sld_parameters")
public interface SldParametersPointer extends PointerBase {

@CField("use_name")
boolean isUseName();
Expand All @@ -940,18 +940,18 @@ public interface LayoutParametersPointer extends PointerBase {
@CField("diagonal_label")
void setDiagonalLabel(boolean diagonalLabel);

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

@CField("topological_coloring")
void setTopologicalColoring(boolean topologicalColoring);

@CField("nodes_infos")
boolean isAddNodesInfos();

@CField("nodes_infos")
void setAddNodesInfos(boolean addNodeInfos);

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

@CField("topological_coloring")
void setTopologicalColoring(boolean topologicalColoring);

@CField("component_library")
CCharPointer getComponentLibrary();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ static void writeSvg(Network network, List<String> voltageLevelIds, int depth, W
.setFixedWidth(800)
.setFixedHeight(600)
.setEdgeNameDisplayed(edgeNameDisplayed);

Predicate<VoltageLevel> filter = !voltageLevelIds.isEmpty()
? getNominalVoltageFilter(network, voltageLevelIds, highNominalVoltageBound, lowNominalVoltageBound, depth)
: VoltageLevelFilter.NO_FILTER;
NadParameters nadParameters = new NadParameters()
.setSvgParameters(svgParameters);

NetworkAreaDiagram.draw(network, writer, nadParameters, filter);
}

Expand Down
Loading

0 comments on commit 443b218

Please sign in to comment.