Skip to content

Commit

Permalink
hash all items
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHsunTsai committed Sep 5, 2024
1 parent cf544f0 commit 7025d71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
* Updated `ViewerSceneObject` with hash ability in order to catch the update from `settings`.

### Removed

Expand All @@ -33,8 +34,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed `Tag` inconsistent height issue.
* Dynamically adjust camera pan delta based on distacne.

* Updated alignright feature to `TextEdit`

### Removed


Expand All @@ -54,7 +53,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Updated callback to `SceneTree`.
* Updated `ObjectSetting` and `CameraSetting` to support setting from config.
* Updated `Slider` to be able change value with `TextEdit`
* Updated `ViewerSceneObject` with hash ability to check if `kwarg` is equal

### Removed

Expand Down
4 changes: 2 additions & 2 deletions src/compas_viewer/components/sceneform.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def scene(self):
return self.viewer.scene

def update(self):
current_scene_objects = {hash(obj) for obj in self.scene.objects}
current_scene_objects = [hash(obj) for obj in self.scene.objects]
if current_scene_objects == self._sceneobjects:
for node in self.scene.traverse("breadthfirst"):
widget = node.attributes.get("widget")
Expand All @@ -78,7 +78,7 @@ def update(self):
self.scrollToItem(widget)

else:
self._sceneobjects = list(self.scene.objects)
self._sceneobjects = [hash(obj) for obj in self.scene.objects]

self.clear()
self.checkbox_columns = {}
Expand Down
10 changes: 3 additions & 7 deletions src/compas_viewer/scene/sceneobject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
from typing import Any
from typing import Optional

Expand Down Expand Up @@ -130,13 +129,10 @@ def __init__(

self._inited = False

def __eq__(self, other) -> bool:
if not isinstance(other, ViewerSceneObject):
return False
return self.settings == other.settings

def __hash__(self):
return hash(tuple(self.settings))
# Convert self.settings.items() to a hashable type (e.g., frozenset) but convert Color objects to tuples
hashable_settings = frozenset((key, (value.rgb255 if isinstance(value, Color) else value)) for key, value in self.settings.items())
return hash(hashable_settings)

@property
def bounding_box(self):
Expand Down

0 comments on commit 7025d71

Please sign in to comment.