Skip to content

GUI files

The GUI module provides the logic to create and validate GUI specific models for a D-Flow FM model.

Generic parsing and serializing functionality comes from the generic hydrolib.core.dflowfm.ini modules.

A .gui file is described by the classes below.

GUI models

Namespace for storing the branches as branches.gui file.

Branch

Bases: INIBasedModel

A branch that is included in the branches.gui file.

Source code in hydrolib/core/dflowfm/gui/models.py
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
class Branch(INIBasedModel):
    """A branch that is included in the branches.gui file."""

    class Comments(INIBasedModel.Comments):
        """Comments for the Branch section."""

        name: Optional[str] = "Unique branch id."
        branchtype: Optional[str] = Field(
            "Channel = 0, SewerConnection = 1, Pipe = 2.", alias="branchType"
        )
        islengthcustom: Optional[str] = Field(
            "branch length specified by user.", alias="isLengthCustom"
        )
        sourcecompartmentname: Optional[str] = Field(
            "Source compartment name this sewer connection is beginning.",
            alias="sourceCompartmentName",
        )
        targetcompartmentname: Optional[str] = Field(
            "Source compartment name this sewer connection is beginning.",
            alias="targetCompartmentName",
        )
        material: Optional[str] = Field(
            "0 = Unknown, 1 = Concrete, 2 = CastIron, 3 = StoneWare, 4 = Hdpe, "
            "5 = Masonry, 6 = SheetMetal, 7 = Polyester, 8 = Polyvinylchlorid, 9 = Steel"
        )

    comments: Comments = Comments()

    _header: Literal["Branch"] = "Branch"

    name: str = Field("name", max_length=255, alias="name")
    branchtype: int = Field(0, alias="branchType")
    islengthcustom: Optional[bool] = Field(True, alias="isLengthCustom")
    sourcecompartmentname: Optional[str] = Field(None, alias="sourceCompartmentName")
    targetcompartmentname: Optional[str] = Field(None, alias="targetCompartmentName")
    material: Optional[int] = Field(None, alias="material")

    def _get_identifier(self, data: dict) -> Optional[str]:
        return data.get("name")

    @model_validator(mode="after")
    def _validate_branch(self) -> "Branch":
        if self.branchtype == 2 and (
            self.sourcecompartmentname is None and self.targetcompartmentname is None
        ):
            raise ValueError(
                "Either sourceCompartmentName or targetCompartmentName should be provided when branchType is 2."
            )

        return self

    @field_validator("branchtype")
    @classmethod
    def _validate_branchtype(cls, branchtype: int):
        allowed_branchtypes = [0, 1, 2]
        if branchtype not in allowed_branchtypes:
            str_allowed_branchtypes = [str(i) for i in allowed_branchtypes]
            error_msg = f"branchType ({branchtype}) is not allowed. Allowed values: {', '.join(str_allowed_branchtypes)}"
            raise ValueError(error_msg)

        return branchtype

    @field_validator("material")
    @classmethod
    def _validate_material(cls, material: int):
        allowed_materials = range(10)
        if material not in allowed_materials:
            str_allowed_materials = [str(i) for i in allowed_materials]
            error_msg = f"material ({material}) is not allowed. Allowed values: {', '.join(str_allowed_materials)}"
            raise ValueError(error_msg)

        return material

Comments

Bases: Comments

Comments for the Branch section.

Source code in hydrolib/core/dflowfm/gui/models.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Comments(INIBasedModel.Comments):
    """Comments for the Branch section."""

    name: Optional[str] = "Unique branch id."
    branchtype: Optional[str] = Field(
        "Channel = 0, SewerConnection = 1, Pipe = 2.", alias="branchType"
    )
    islengthcustom: Optional[str] = Field(
        "branch length specified by user.", alias="isLengthCustom"
    )
    sourcecompartmentname: Optional[str] = Field(
        "Source compartment name this sewer connection is beginning.",
        alias="sourceCompartmentName",
    )
    targetcompartmentname: Optional[str] = Field(
        "Source compartment name this sewer connection is beginning.",
        alias="targetCompartmentName",
    )
    material: Optional[str] = Field(
        "0 = Unknown, 1 = Concrete, 2 = CastIron, 3 = StoneWare, 4 = Hdpe, "
        "5 = Masonry, 6 = SheetMetal, 7 = Polyester, 8 = Polyvinylchlorid, 9 = Steel"
    )

BranchGeneral

Bases: INIGeneral

The branches.gui file's [General] section with file meta data.

Source code in hydrolib/core/dflowfm/gui/models.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class BranchGeneral(INIGeneral):
    """The branches.gui file's `[General]` section with file meta data."""

    class Comments(INIBasedModel.Comments):
        """Comments for the BranchGeneral section."""

        fileversion: Optional[str] = Field(
            "File version. Do not edit this.", alias="fileVersion"
        )
        filetype: Optional[str] = Field(
            "File type. Should be 'branches'. Do not edit this.",
            alias="fileType",
        )

    comments: Comments = Comments()
    _header: Literal["General"] = "General"
    fileversion: str = Field("2.00", alias="fileVersion")
    filetype: Literal["branches"] = Field("branches", alias="fileType")

Comments

Bases: Comments

Comments for the BranchGeneral section.

Source code in hydrolib/core/dflowfm/gui/models.py
17
18
19
20
21
22
23
24
25
26
class Comments(INIBasedModel.Comments):
    """Comments for the BranchGeneral section."""

    fileversion: Optional[str] = Field(
        "File version. Do not edit this.", alias="fileVersion"
    )
    filetype: Optional[str] = Field(
        "File type. Should be 'branches'. Do not edit this.",
        alias="fileType",
    )

BranchModel

Bases: INIModel

The overall branch model that contains the contents of one branches.gui file.

This model is not referenced under a FMModel.

Attributes:

Name Type Description
general BranchGeneral

[General] block with file metadata.

branch(List[Branch]) BranchGeneral

List of [Branch] blocks for all branches.

Source code in hydrolib/core/dflowfm/gui/models.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class BranchModel(INIModel):
    """
    The overall branch model that contains the contents of one branches.gui file.

    This model is not referenced under a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel].

    Attributes:
        general (BranchGeneral): `[General]` block with file metadata.
        branch(List[Branch]): List of `[Branch]` blocks for all branches.
    """

    general: BranchGeneral = BranchGeneral()
    branch: Annotated[List[Branch], BeforeValidator(ensure_list)] = Field(
        default_factory=list
    )

    @classmethod
    def _ext(cls) -> str:
        return ".gui"

    @classmethod
    def _filename(cls) -> str:
        return "branches"