Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 149 additions & 15 deletions src/czml3/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ class Color(BaseCZMLObject, Interpolatable, Deletable):
)
"""The color specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.rgba, self.rgbaf, self.reference)) != 1:
raise TypeError("Only one of rgba, rgbaf or reference must be given")
return self

@field_validator("rgba")
@classmethod
def validate_rgba(cls, c):
Expand Down Expand Up @@ -527,13 +535,23 @@ class EllipsoidRadii(BaseCZMLObject, Interpolatable, Deletable):

See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/EllipsoidRadii>`__ for it's definition."""

cartesian: Cartesian3Value | list[float] | TimeIntervalCollection = Field()
cartesian: Cartesian3Value | list[float] | TimeIntervalCollection | None = Field(
default=None
)
"""The radii specified as a three-dimensional Cartesian value `[X, Y, Z]`, in world coordinates in meters. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Cartesian3Value>`__ for it's definition."""
reference: None | ReferenceValue | str | TimeIntervalCollection = Field(
default=None
)
"""The radii specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.cartesian, self.reference)) != 1:
raise TypeError("Only one of cartesian or reference must be given")
return self

@field_validator("cartesian")
@classmethod
def validate_cartesian(cls, r):
Expand Down Expand Up @@ -818,6 +836,14 @@ class ArcType(BaseCZMLObject, Deletable):
)
"""The arc type specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.arcType, self.reference)) != 1:
raise TypeError("Only one of arcType or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand All @@ -838,6 +864,14 @@ class ShadowMode(BaseCZMLObject, Deletable):
)
"""The shadow mode specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.shadowMode, self.reference)) != 1:
raise TypeError("Only one of shadowMode or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand All @@ -860,6 +894,17 @@ class ClassificationType(BaseCZMLObject, Deletable):
)
"""The classification type specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if (
sum(val is not None for val in (self.classificationType, self.reference))
!= 1
):
raise TypeError("Only one of classificationType or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand All @@ -882,6 +927,22 @@ class DistanceDisplayCondition(BaseCZMLObject, Interpolatable, Deletable):
)
"""The value specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if (
sum(
val is not None
for val in (self.distanceDisplayCondition, self.reference)
)
!= 1
):
raise TypeError(
"Only one of distanceDisplayCondition or reference must be given"
)
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand Down Expand Up @@ -1178,6 +1239,14 @@ class BoxDimensions(BaseCZMLObject, Interpolatable, Deletable):
)
"""The dimensions specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.cartesian, self.reference)) != 1:
raise TypeError("Only one of cartesian or reference must be given")
return self

@field_validator("cartesian")
@classmethod
def validate_cartesian(cls, r):
Expand Down Expand Up @@ -1226,8 +1295,13 @@ class RectangleCoordinates(BaseCZMLObject, Interpolatable, Deletable):
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.wsen, self.wsenDegrees)) != 1:
raise TypeError("One of wsen or wsenDegrees must be given")
if (
sum(
val is not None for val in (self.wsen, self.wsenDegrees, self.reference)
)
!= 1
):
raise TypeError("Only one of wsen, wsenDegrees or reference must be given")
return self

@field_validator("reference")
Expand All @@ -1252,6 +1326,14 @@ class EyeOffset(BaseCZMLObject, Deletable):
)
"""The eye offset specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.cartesian, self.reference)) != 1:
raise TypeError("Only one of cartesian or reference must be given")
return self

@field_validator("cartesian")
@classmethod
def validate_cartesian(cls, r):
Expand Down Expand Up @@ -1281,6 +1363,14 @@ class HeightReference(BaseCZMLObject, Deletable):
)
"""The height reference specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.heightReference, self.reference)) != 1:
raise TypeError("Only one of heightReference or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand All @@ -1303,6 +1393,14 @@ class ColorBlendMode(BaseCZMLObject, Deletable):
)
"""The color blend mode specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.colorBlendMode, self.reference)) != 1:
raise TypeError("Only one of colorBlendMode or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand All @@ -1323,6 +1421,14 @@ class CornerType(BaseCZMLObject, Deletable):
)
"""The corner style specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.cornerType, self.reference)) != 1:
raise TypeError("Only one of cornerType or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand Down Expand Up @@ -1478,6 +1584,14 @@ class NearFarScalar(BaseCZMLObject, Interpolatable, Deletable):
)
"""The value specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.nearFarScalar, self.reference)) != 1:
raise TypeError("Only one of nearFarScalar or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand Down Expand Up @@ -1550,6 +1664,14 @@ class Orientation(BaseCZMLObject, Interpolatable, Deletable):
velocityReference: None | str | TimeIntervalCollection = Field(default=None)
"""The orientation specified as the normalized velocity vector of a position property. The reference must be to a position property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/VelocityReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.unitQuaternion, self.reference)) != 1:
raise TypeError("Only one of unitQuaternion or reference must be given")
return self

@field_validator("reference")
@classmethod
def validate_reference(cls, r):
Expand Down Expand Up @@ -1619,10 +1741,18 @@ class Uri(BaseCZMLObject, Deletable):

uri: None | str | TimeIntervalCollection = Field(default=None)
"""The URI value."""
# reference: None | ReferenceValue | str | TimeIntervalCollection = Field(
# default=None
# )
# """The color specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""
reference: None | ReferenceValue | str | TimeIntervalCollection = Field(
default=None
)
"""The color specified as a reference to another property. See `here <https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/ReferenceValue>`__ for it's definition."""

@model_validator(mode="after")
def checks(self):
if self.delete:
return self
if sum(val is not None for val in (self.uri, self.reference)) != 1:
raise TypeError("Only one of uri or reference must be given")
return self

@field_validator("uri")
@classmethod
Expand All @@ -1641,13 +1771,17 @@ def _check_uri(cls, url: str):
# "uri must be a URL, a data URI or base64 encoded string."
# )

# @field_validator("reference")
# @classmethod
# def validate_reference(cls, r):
# if isinstance(r, str):
# return ReferenceValue(value=r)
# return r
@field_validator("reference")
@classmethod
def validate_reference(cls, r):
if isinstance(r, str):
return ReferenceValue(value=r)
return r

@model_serializer
def custom_serializer(self) -> None | str | TimeIntervalCollection:
return self.uri
def custom_serializer(
self,
) -> None | str | dict[str, bool] | TimeIntervalCollection:
if self.delete:
return {"delete": True}
return self.uri if self.uri is not None else str(self.reference)
Loading