From d8ed051a92a274e4d19fd6090a16c0d3e378fc5b Mon Sep 17 00:00:00 2001 From: "Federico M. Facca" Date: Wed, 11 Oct 2023 19:06:55 +0200 Subject: [PATCH] don't generate not used classes --- CGMES_3.0_modernpython/PositionPoint.py | 46 +++++++++++++++++++++++++ modernpython/langPack.py | 30 +++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 CGMES_3.0_modernpython/PositionPoint.py diff --git a/CGMES_3.0_modernpython/PositionPoint.py b/CGMES_3.0_modernpython/PositionPoint.py new file mode 100644 index 0000000..e37b1d5 --- /dev/null +++ b/CGMES_3.0_modernpython/PositionPoint.py @@ -0,0 +1,46 @@ +""" +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 .Base import DataclassConfig, Profile +from .Base import Base + +@dataclass(config=DataclassConfig) +class PositionPoint(Base): + """ + Set of spatial coordinates that determine a point, defined in the coordinate system specified in + 'Location.CoordinateSystem'. Use a single position point instance to describe a point-oriented location. Use a + sequence of position points to describe a line-oriented object (physical location of non-point oriented + objects like cables or lines), or area of an object (like a substation or a geographical zone - in this case, + have first and last position point with the same values). + + Location: Location described by this position point. + sequenceNumber: Zero-relative sequence number of this point within a series of points. + xPosition: X axis position. + yPosition: Y axis position. + zPosition: (if applicable) Z axis position. + """ + + Location : Optional[str] = Field(default=None, in_profiles = [Profile.GL, ]) + + sequenceNumber : int = Field(default=0, in_profiles = [Profile.GL, ]) + + xPosition : str = Field(default="", in_profiles = [Profile.GL, ]) + + yPosition : str = Field(default="", in_profiles = [Profile.GL, ]) + + zPosition : str = Field(default="", in_profiles = [Profile.GL, ]) + + + + @cached_property + def possible_profiles(self)->set[Profile]: + """ + A resource can be used by multiple profiles. This is the set of profiles + where this element can be found. + """ + return { Profile.GL, } diff --git a/modernpython/langPack.py b/modernpython/langPack.py index 02a5d91..6555bd6 100644 --- a/modernpython/langPack.py +++ b/modernpython/langPack.py @@ -32,6 +32,17 @@ def location(version): template_files = [{"filename": "cimpy_class_template.mustache", "ext": ".py"}] enum_template_files = [{"filename": "pydantic_enum_template.mustache", "ext": ".py"}] +PRIMITIVE_CLASSES = [ + "Float", + "Integer", + "String", + "Boolean", + "Date", + "DateTime", + "MonthDay", + "Decimal", + ] + def get_class_location(class_name, class_map, version): # Check if the current class has a parent class if class_map[class_name].superClass(): @@ -105,9 +116,26 @@ def set_enum_classes(new_enum_classes): def set_float_classes(new_float_classes): return +def has_unit_attribute(attributes): + for attr in attributes: + if attr["label"] == "unit": + return True + return False def run_template(version_path, class_details): - if class_details["has_instances"] == True: + if ( + # Primitives are never used in the in memory representation but only for + # the schema + ( + class_details["class_name"] + in PRIMITIVE_CLASSES + ) + # Datatypes based on primitives are never used in the in memory + # representation but only for the schema + or class_details["is_a_float"] == True + ): + return + elif class_details["has_instances"] == True: run_template_enum(version_path, class_details, enum_template_files) else: run_template_schema(version_path, class_details, template_files)