Skip to content

Commit

Permalink
feat(model): use designates_type with Event
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed May 22, 2024
1 parent 9ee3eb3 commit 05407e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 103 deletions.
52 changes: 5 additions & 47 deletions model/itk-viewer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ classes:
type:
description: >-
The type of the Zarr store model.
range: StoreModelType
designates_type: true
range: string
required: true

DirectoryStore:
Expand Down Expand Up @@ -172,10 +173,10 @@ classes:
class_uri: viewer:Event
attributes:
type:
identifier: true
designates_type: true
description: >-
The type of the event.
range: EventType
range: string
required: true

ViewerEvent:
Expand All @@ -184,9 +185,6 @@ classes:
description: >-
A ViewerEvent is an Event that can be sent to a Viewer.
class_uri: viewer:ViewerEvent
slot_usage:
type:
range: ViewerEventType

SetImageEvent:
is_a: ViewerEvent
Expand All @@ -207,9 +205,6 @@ classes:
description: >-
A RendererEvent is an Event supported by a Renderer.
class_uri: viewer:RendererEvent
slot_usage:
type:
range: RendererEventType

RenderEvent:
is_a: RendererEvent
Expand Down Expand Up @@ -247,11 +242,6 @@ slots:
required: true

enums:
EventType:
description: >-
The types of events that can be sent to actors.
enum_uri: viewer:EventType

UnknownEventAction:
description: >-
The types of actions that can be taken when an unknown event is received.
Expand All @@ -265,36 +255,4 @@ enums:
Log a warning and ignore the event.
Error:
description: >-
Throw an error.
ViewerEventType:
description: >-
The types of events that can be sent to viewers.
enum_uri: viewer:ViewerEventType
inherits: EventType
permissible_values:
SetImage:
description: >-
Set an image to be displayed in the viewer.
RendererEventType:
description: >-
The types of render events that can be sent to renderers.
enum_uri: viewer:RenderEventType
inherits: EventType
permissible_values:
Render:
description: >-
A render event is a message that instructs a renderer to render a scene to an in-memory RGB image.
StoreModelType:
description: >-
The types of Zarr store models.
enum_uri: viewer:StoreModelType
permissible_values:
Directory:
description: >-
A Zarr store that is backed by a directory on the file system.
FSStore:
description: >-
A Zarr store that can be wrapped an fsspec.FSMap in Python to give access to arbitrary filesystems.
Throw an error.
66 changes: 10 additions & 56 deletions packages/viewer/python/itkviewer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ class ConfiguredBaseModel(BaseModel):



class EventType(str):
"""
The types of events that can be sent to actors.
"""

dummy = "dummy"


class UnknownEventAction(str, Enum):
"""
The types of actions that can be taken when an unknown event is received.
Expand All @@ -49,35 +41,6 @@ class UnknownEventAction(str, Enum):



class ViewerEventType(str, Enum):
"""
The types of events that can be sent to viewers.
"""
# Set an image to be displayed in the viewer.
SetImage = "SetImage"



class RendererEventType(str, Enum):
"""
The types of render events that can be sent to renderers.
"""
# A render event is a message that instructs a renderer to render a scene to an in-memory RGB image.
Render = "Render"



class StoreModelType(str, Enum):
"""
The types of Zarr store models.
"""
# A Zarr store that is backed by a directory on the file system.
Directory = "Directory"
# A Zarr store that can be wrapped an fsspec.FSMap in Python to give access to arbitrary filesystems.
FSStore = "FSStore"



class Actor(ConfiguredBaseModel):
"""
In the Actor Model mathematical of computation, an actor is a computational entity that, in response to a message it receives, can concurrently:
Expand Down Expand Up @@ -117,19 +80,11 @@ class Image(ConfiguredBaseModel):



class ImageDataUri(ConfiguredBaseModel):
"""
A serialized itk-wasm Image to be displayed in the viewer, compressed and base64 encoded.
"""
uri: str = Field(..., description="""The URI of the image data.""")



class StoreModel(ConfiguredBaseModel):
"""
Parameters of a Zarr store following the data model implied by Zarr-Python.
"""
type: StoreModelType = Field(..., description="""The type of the Zarr store model.""")
type: Literal["StoreModel"] = Field("StoreModel", description="""The type of the Zarr store model.""")



Expand All @@ -138,7 +93,7 @@ class DirectoryStore(StoreModel):
A Zarr store that is backed by a directory on the file system.
"""
path: str = Field(..., description="""The path to the directory on the file system that contains the Zarr store.""")
type: StoreModelType = Field(..., description="""The type of the Zarr store model.""")
type: Literal["DirectoryStore"] = Field("DirectoryStore", description="""The type of the Zarr store model.""")



Expand All @@ -147,16 +102,16 @@ class FSStore(StoreModel):
A Zarr store that can be wrapped an fsspec.FSMap in Python to give access to arbitrary filesystems
"""
url: str = Field(..., description="""Protocol and path, like “s3://bucket/root.zarr” or \"https://example.com/image.ome.zarr\".""")
type: StoreModelType = Field(..., description="""The type of the Zarr store model.""")
type: Literal["FSStore"] = Field("FSStore", description="""The type of the Zarr store model.""")



class ImageData(ConfiguredBaseModel):
"""
Image data displayed in the viewer.
"""
dataUri: Optional[ImageDataUri] = Field(None, description="""The image data.""")
store: Optional[StoreModel] = Field(None, description="""The OME-Zarr store model for the image data.""")
imageJson: Optional[str] = Field(None, description="""The image data in JSON format. An ITK-Wasm Image with the pixel data zstd compressed and base64-encoded.""")
store: Optional[Union[StoreModel,DirectoryStore,FSStore]] = Field(None, description="""The OME-Zarr store model for the image data.""")



Expand Down Expand Up @@ -192,15 +147,15 @@ class Event(ConfiguredBaseModel):
"""
An event is a message that can be sent to an actor. The actor can respond to the event by changing its state, sending messages to other actors, or creating new actors.
"""
type: EventType = Field(..., description="""The type of the event.""")
type: Literal["Event"] = Field("Event", description="""The type of the event.""")



class ViewerEvent(Event):
"""
A ViewerEvent is an Event that can be sent to a Viewer.
"""
type: ViewerEventType = Field(..., description="""The type of the event.""")
type: Literal["ViewerEvent"] = Field("ViewerEvent", description="""The type of the event.""")



Expand All @@ -210,23 +165,23 @@ class SetImageEvent(ViewerEvent):
"""
image: Image = Field(..., description="""The image to be displayed in the viewer.""")
name: Optional[str] = Field(None, description="""The name of the image to be displayed in the viewer.""")
type: ViewerEventType = Field(..., description="""The type of the event.""")
type: Literal["SetImageEvent"] = Field("SetImageEvent", description="""The type of the event.""")



class RendererEvent(Event):
"""
A RendererEvent is an Event supported by a Renderer.
"""
type: RendererEventType = Field(..., description="""The type of the event.""")
type: Literal["RendererEvent"] = Field("RendererEvent", description="""The type of the event.""")



class RenderEvent(RendererEvent):
"""
A render event is a message that instructs a renderer to render a scene to an in-memory RGB image.
"""
type: RendererEventType = Field(..., description="""The type of the event.""")
type: Literal["RenderEvent"] = Field("RenderEvent", description="""The type of the event.""")



Expand All @@ -237,7 +192,6 @@ class RenderEvent(RendererEvent):
Viewer.model_rebuild()
Viewport.model_rebuild()
Image.model_rebuild()
ImageDataUri.model_rebuild()
StoreModel.model_rebuild()
DirectoryStore.model_rebuild()
FSStore.model_rebuild()
Expand Down

0 comments on commit 05407e5

Please sign in to comment.