Skip to content
Draft
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
90 changes: 65 additions & 25 deletions src/opengeodeweb_viewer/rpc/viewer/viewer_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ def renderNow(self, rpc_params: RpcParams) -> None:
self.render()

@exportRpc(viewer_prefix + viewer_schemas_dict["hover_highlight"]["rpc"])
def setHoverHighlight(self, rpc_params: RpcParams) -> None:
def setHoverHighlight(
self, rpc_params: RpcParams
) -> dict[str, str | int | None | dict[str, list[float] | float]]:
validate_schema(
rpc_params, self.viewer_schemas_dict["hover_highlight"], self.viewer_prefix
)
Expand All @@ -313,34 +315,72 @@ def setHoverHighlight(self, rpc_params: RpcParams) -> None:
picker.Pick(params.x, params.y, 0, self.get_renderer())
self.clearHoverHighlights(params.ids)
actor = picker.GetActor()
pipeline = next(
(
self.get_vtk_pipeline(id)
for id in params.ids
if self.get_vtk_pipeline(id).actor == actor
),
None,
pipeline_id = next(
(id for id in params.ids if self.get_vtk_pipeline(id).actor == actor), None
)
if pipeline:
id_to_select = (
picker.GetCellId()
id_to_select = (
picker.GetCellId()
if params.field_type == schemas.FieldType.CELL
else picker.GetPointId()
)

if not pipeline_id or id_to_select == -1:
self.render(-1)
return {}

pipeline = self.get_vtk_pipeline(pipeline_id)
dataset = None
geode_id = None
if isinstance(pipeline.mapper, vtkCompositePolyDataMapper):
flat_index = picker.GetFlatBlockIndex()
dataset = (
pipeline.blockDataSets[flat_index]
if 0 <= flat_index < len(pipeline.blockDataSets)
else None
)
geode_id = (
pipeline.blockGeodeIds[flat_index]
if 0 <= flat_index < len(pipeline.blockGeodeIds)
else None
)

self.updateHoverHighlight(
pipeline, id_to_select, params.field_type.value, dataset
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Argument 4 to "updateHoverHighlight" of "VtkView" has incompatible type "vtkDataObject | None"; expected "vtkDataSet | None" [arg-type]

)
self.render(-1)

data_obj = dataset or pipeline.reader.GetOutputDataObject(0)
data_attributes = {}
if isinstance(data_obj, vtkDataSet):
field_data = (
data_obj.GetCellData()
if params.field_type == schemas.FieldType.CELL
else picker.GetPointId()
else data_obj.GetPointData()
)
if id_to_select != -1:
dataset = None
if isinstance(pipeline.mapper, vtkCompositePolyDataMapper):
flat_index = picker.GetFlatBlockIndex()
block = (
pipeline.blockDataSets[flat_index]
if 0 <= flat_index < len(pipeline.blockDataSets)
else None
for array_index in range(field_data.GetNumberOfArrays()):
array = field_data.GetArray(array_index)
if array and array.GetName():
num_comps = array.GetNumberOfComponents()
component_values = [
array.GetComponent(id_to_select, component_index)
for component_index in range(num_comps)
]
data_attributes[array.GetName()] = (
component_values[0] if num_comps == 1 else component_values
)
dataset = block if isinstance(block, vtkDataSet) else None
self.updateHoverHighlight(
pipeline, id_to_select, params.field_type.value, dataset
)
self.render(-1)

if params.field_type == schemas.FieldType.POINT:
point_coordinates = data_obj.GetPoint(id_to_select)
if point_coordinates:
data_attributes["coordinates"] = list(point_coordinates)

return {
"id": pipeline_id,
"picked_id": id_to_select,
"field_type": params.field_type.value,
"geode_id": geode_id,
"attributes": data_attributes,
}

@exportRpc(viewer_prefix + viewer_schemas_dict["set_z_scaling"]["rpc"])
def setZScaling(self, rpc_params: RpcParams) -> None:
Expand Down
Loading