zaphiro-technologies / cimgen

Code generation from CIM data model for several programming languages
Apache License 2.0
0 stars 0 forks source link

[Feature] Create a dataclass for primitives and generate a file for each primitive #10

Open chicco785 opened 1 month ago

chicco785 commented 1 month ago

Is your feature request related to a problem? Please describe the problem.

Primitives are now generated as classes, e.g.:

"""
Generated from the CGMES 3 files via cimgen: https://github.com/sogno-platform/cimgen
"""

from functools import cached_property
from typing import Optional
from pydantic import Field
from pydantic.dataclasses import dataclass
from ..utils.profile import BaseProfile, Profile

from ..utils.base import Base

@dataclass
class Float(Base):
    """
    A floating point number. The range is unspecified and not limited.

    """

    # No attributes defined for this class.

    @cached_property
    def possible_profiles(self)->set[BaseProfile]:
        """
        A resource can be used by multiple profiles. This is the set of profiles
        where this element can be found.
        """
        return { Profile.DL, Profile.DY, Profile.EQ, Profile.EQBD, Profile.OP, Profile.SC, Profile.SSH, Profile.SV,  }

which is no sense, they should be used to annotate cim classes fields and that's all.

Describe the solution you'd like

Float = Primitive(name="Float", type=float, profiles=[Profile.EQBD, Profile.OP, Profile.SSH, Profile.EQ, Profile.DY, Profile.DL, Profile.SV, Profile.SC, ])

...

@dataclass(config=DataclassConfig)
class AnalogLimit(Limit):
    """
    Limit values for Analog measurements.

    value: The value to supervise against.
    LimitSet: The set of limits.
    """

    value : float = Field(default=0.0, in_profiles = [Profile.OP, ], data_type = Float,alias = "value")
    limitSet : AnalogLimitSet = Field(default=None, in_profiles = [Profile.OP, ], alias = "LimitSet")

    val_limitSet_wrap = field_validator("limitSet", mode="wrap")(cyclic_references_validator)

    @cached_property
    def possible_profiles(self)->set[BaseProfile]:
        """
        A resource can be used by multiple profiles. This is the set of profiles
        where this element can be found.
        """
        return { Profile.OP,  }

Additional context

No response