22
33from typing import Any , Dict , List
44
5- from pydantic import (
6- BaseModel ,
7- ConfigDict ,
8- Field ,
9- SerializationInfo ,
10- SerializerFunctionWrapHandler ,
11- field_validator ,
12- model_serializer ,
13- )
5+ from pydantic import BaseModel , ConfigDict , Field , field_validator
146
157from ansys .visor .viewer .core .visor_colors import VisorPartDefaults
168from ansys .visor .viewer .core .visor_logging import VisorDefaultLogger
@@ -34,10 +26,9 @@ class RuntimePartProperties(BaseModel):
3426 No field holds ``None`` except ``color_variable``, whose ``None`` is the
3527 resolved value "not coloured by a variable".
3628
37- The wire carries the reference flat, as ``variableId`` and
38- ``variableComponent``. With no reference, ``variableId`` is ``null`` and
39- ``variableComponent`` is absent; under ``exclude_none`` ``variableId`` is
40- absent too. Callers pass ``by_alias=True`` so the keys stay camelCase.
29+ The wire carries the reference nested, as ``colorVariable`` holding
30+ ``variableId`` and ``variableComponent``, or ``null`` with no reference.
31+ Callers pass ``by_alias=True`` so the keys stay camelCase.
4132
4233 id: The part's scene-graph node ID.
4334 opacity: Between 0.0 (fully transparent) and 1.0 (fully opaque).
@@ -53,23 +44,7 @@ class RuntimePartProperties(BaseModel):
5344 visible : bool
5445 selected : bool
5546 diffuse_rgb : List [float ] = Field (alias = "diffuseRgb" )
56- color_variable : VariableReference | None
57-
58- @model_serializer (mode = "wrap" )
59- def _serialize (self , handler : SerializerFunctionWrapHandler , info : SerializationInfo ) -> dict :
60- """Emit the reference flat as variableId/variableComponent; with none, variableId is null unless
61- exclude_none."""
62- data : dict = handler (self )
63- data .pop ("color_variable" , None )
64- id_key = "variableId" if info .by_alias else "variable_id"
65- component_key = "variableComponent" if info .by_alias else "variable_component"
66- reference = self .color_variable
67- if reference is not None :
68- data [id_key ] = reference .variable_id
69- data [component_key ] = reference .variable_component
70- elif not info .exclude_none :
71- data [id_key ] = None
72- return data
47+ color_variable : VariableReference | None = Field (alias = "colorVariable" )
7348
7449 @classmethod
7550 def default_for (cls , part_id : int ) -> "RuntimePartProperties" :
0 commit comments