Skip to content

Commit

Permalink
don't generate not used classes
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco785 committed Oct 11, 2023
1 parent 4131466 commit d8ed051
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
46 changes: 46 additions & 0 deletions CGMES_3.0_modernpython/PositionPoint.py
Original file line number Diff line number Diff line change
@@ -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, }
30 changes: 29 additions & 1 deletion modernpython/langPack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d8ed051

Please sign in to comment.