# Copyright (C) Stichting Deltares 2021. All rights reserved. # # This file is part of the Dam Python Interface. # # The Dam Python Interface is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # All names, logos, and references to "Deltares" are registered trademarks of # Stichting Deltares and remain full property of Stichting Deltares at all times. # All rights reserved. from .base_class import BaseDataClass from typing import List from enum import IntEnum from pydantic import root_validator import lxml.etree as et class PointTypeEnum(IntEnum): """ Enumeration class for the characteristic point type. """ NONE = 0 SurfaceLevelOutside = 1 DikeToeAtRiver = 5 ShoulderTopOutside = 6 ShoulderBaseOutside = 7 DikeTopAtRiver = 8 DikeLine = 9 TrafficLoadOutside = 10 TrafficLoadInside = 11 DikeTopAtPolder = 12 ShoulderBaseInside = 13 ShoulderTopInside = 14 DikeToeAtPolder = 15 DitchDikeSide = 16 BottomDitchDikeSide = 17 BottomDitchPolderSide = 18 DitchPolderSide = 19 SurfaceLevelInside = 25 class Point(BaseDataClass): """ Dataclass that contains characteristic point corresponding to the SurfaceLine class. :param X: X coordinate. :param Z: Z coordinate. :param PointType: type of the characteristic point. """ X: float Z: float PointType: PointTypeEnum class SurfaceLine(BaseDataClass): """ Dataclass that contains geometry information for a profile :param Name: Name of the surface line. :param Points: geometry information of a profile. """ Name: str Points: List[Point] = [] @staticmethod def is_type_in_list(list_of_points: Point, required_point_type: Point) -> bool: for point in list_of_points: if point.PointType == required_point_type: return True return False @staticmethod def raise_error_if_point_does_not_exist( list_of_points: Point, name: str, required_point_type: Point, ) -> None: if not (SurfaceLine.is_type_in_list(list_of_points, required_point_type)): raise ValueError( f"Set Characteristic points {name} is not complete. \ Characteristic point {required_point_type.name} is missing." ) @root_validator def check_that_necessary_points_exist(cls, values: tuple) -> tuple: """ Property validator of Points of the SurfaceLine class. Required characteristic points are: * Surface level outside * Dike toe at river * Dike top at river * Dike top at polder * Dike toe at polder * Surface level inside """ required_points = [ PointTypeEnum.SurfaceLevelOutside, PointTypeEnum.DikeToeAtRiver, PointTypeEnum.DikeTopAtRiver, PointTypeEnum.DikeTopAtPolder, PointTypeEnum.DikeToeAtPolder, PointTypeEnum.SurfaceLevelInside, ] for required_point in required_points: SurfaceLine.raise_error_if_point_does_not_exist( values.get("Points"), values.get("Name"), required_point ) return values def serialize(self) -> et.Element: surface_line_root = et.Element("SurfaceLine") surface_line_root.set("Name", self.Name) points_root = et.SubElement(surface_line_root, "Points") for point in self.Points: point_root = et.SubElement(points_root, "Point") point_root.set("X", str(point.X)) point_root.set("Z", str(point.Z)) point_root.set("PointType", str(point.PointType.value)) return surface_line_root