Skip to content

Commit

Permalink
Deal with backward compatibility (second try)
Browse files Browse the repository at this point in the history
Signed-off-by: Sophie Frasnedo <sophie.frasnedo@rte-france.com>
  • Loading branch information
So-Fras committed Oct 11, 2023
1 parent b95144c commit 123df9c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
9 changes: 6 additions & 3 deletions pypowsybl/network/impl/layout_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# SPDX-License-Identifier: MPL-2.0
#
from .sld_parameters import SldParameters
from .parent_parameters import ParentParameters


class LayoutParameters:
class LayoutParameters(ParentParameters):
"""
This class is only used for backward compatibility and represents sld parameters for a single line diagram svg generation."""
This class is only used for backward compatibility and represents sld parameters for a single line diagram svg
generation."""

def __init__(self, use_name: bool = False, center_name: bool = False, diagonal_label: bool = False, topological_coloring: bool = True, nodes_infos: bool = False, component_library: str = 'Convergence'):
def __init__(self, use_name: bool = False, center_name: bool = False, diagonal_label: bool = False,
topological_coloring: bool = True, nodes_infos: bool = False, component_library: str = 'Convergence'):
self._use_name = use_name
self._center_name = center_name
self._diagonal_label = diagonal_label
Expand Down
48 changes: 25 additions & 23 deletions pypowsybl/network/impl/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
from .node_breaker_topology import NodeBreakerTopology
from .sld_parameters import SldParameters
from .layout_parameters import LayoutParameters
from .parent_parameters import ParentParameters
from .svg import Svg
from .util import create_data_frame_from_series_array, ParamsDict


class Network: # pylint: disable=too-many-public-methods

def __init__(self, handle: _pp.JavaHandle):
Expand Down Expand Up @@ -178,7 +180,7 @@ def reduce(self, v_min: float = 0, v_max: float = sys.float_info.max, ids: List[
_pp.reduce_network(self._handle, v_min, v_max, ids, vls, depths, with_dangling_lines)

def write_single_line_diagram_svg(self, container_id: str, svg_file: PathOrStr, metadata_file: PathOrStr = None,
parameters: SldParameters = None) -> None:
parameters: ParentParameters = None) -> None:
"""
Create a single line diagram in SVG format from a voltage level or a substation and write to a file.
Expand All @@ -190,21 +192,20 @@ def write_single_line_diagram_svg(self, container_id: str, svg_file: PathOrStr,
"""

svg_file = path_to_str(svg_file)
p = parameters._to_c_parameters() if parameters is not None else _pp.SldParameters() # pylint: disable=protected-access
_pp.write_single_line_diagram_svg(self._handle, container_id, svg_file,
'' if metadata_file is None else path_to_str(metadata_file), p)


def write_single_line_diagram_svg(self, container_id: str, svg_file: PathOrStr, metadata_file: PathOrStr = None,
parameters: LayoutParameters = None) -> None:
"""
Ensure backward compatibility for get_single_line_diagram(self, container_id: str, parameters: SldParameters = None) -> Svg
"""
warnings.warn("LayoutParameters is deprecated, use SldParameters instead", DeprecationWarning)
p = _pp.SldParameters()

sld_parameters = parameters._to_sld_parameters() if parameters is not None else None
write_single_line_diagram_svg(self, container_id, svg_file, metadata_file, sld_parameters)
if isinstance(parameters, SldParameters) and parameters is not None:
p = parameters._to_c_parameters() # pylint: disable=protected-access
elif isinstance(parameters, LayoutParameters) and parameters is not None:
warnings.warn("LayoutParameters is deprecated, use SldParameters instead", DeprecationWarning)
sld_parameters = parameters._to_sld_parameters() # pylint: disable=protected-access
p = sld_parameters._to_c_parameters() # pylint: disable=protected-access
elif not isinstance(parameters, SldParameters) and not isinstance(parameters, LayoutParameters):
warnings.warn("Wrong class for single-line-diagram parameters, switching to default parameters")

_pp.write_single_line_diagram_svg(self._handle, container_id, svg_file,
'' if metadata_file is None else path_to_str(metadata_file), p)

def get_single_line_diagram(self, container_id: str, parameters: SldParameters = None) -> Svg:
"""
Expand All @@ -218,18 +219,19 @@ def get_single_line_diagram(self, container_id: str, parameters: SldParameters =
the single line diagram
"""

p = parameters._to_c_parameters() if parameters is not None else _pp.SldParameters() # pylint: disable=protected-access
svg_and_metadata: List[str] = _pp.get_single_line_diagram_svg_and_metadata(self._handle, container_id, p)
return Svg(svg_and_metadata[0], svg_and_metadata[1])
p = _pp.SldParameters()

def get_single_line_diagram(self, container_id: str, parameters: LayoutParameters = None) -> Svg:
"""
Ensure backward compatibility for get_single_line_diagram(self, container_id: str, parameters: SldParameters = None) -> Svg
"""
if isinstance(parameters, SldParameters) and parameters is not None:
p = parameters._to_c_parameters() # pylint: disable=protected-access
elif isinstance(parameters, LayoutParameters) and parameters is not None:
warnings.warn("LayoutParameters is deprecated, use SldParameters instead", DeprecationWarning)
sld_parameters = parameters._to_sld_parameters() # pylint: disable=protected-access
p = sld_parameters._to_c_parameters() # pylint: disable=protected-access
elif not isinstance(parameters, SldParameters) and not isinstance(parameters, LayoutParameters):
warnings.warn("Wrong class for single-line-diagram parameters, switching to default parameters")

warnings.warn("LayoutParameters is deprecated, use SldParameters instead", DeprecationWarning)
sld_parameters = parameters._to_sld_parameters() if parameters is not None else None
get_single_line_diagram(self, container_id, sld_parameters)
svg_and_metadata: List[str] = _pp.get_single_line_diagram_svg_and_metadata(self._handle, container_id, p)
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,
Expand Down
14 changes: 14 additions & 0 deletions pypowsybl/network/impl/parent_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2023, RTE (http://www.rte-france.com)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
#

class ParentParameters:
"""
This class is only used for backward compatibility and represents the parent class of LayoutParameters (
deprecated) and SldParameters."""

def __init__(self):
pass
3 changes: 2 additions & 1 deletion pypowsybl/network/impl/sld_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# SPDX-License-Identifier: MPL-2.0
#
import pypowsybl._pypowsybl as _pp
from .parent_parameters import ParentParameters


class SldParameters:
class SldParameters(ParentParameters):
"""
This class represents sld parameters for a single line diagram svg generation."""

Expand Down

0 comments on commit 123df9c

Please sign in to comment.