Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHsunTsai committed Jun 26, 2024
1 parent a5c0fd6 commit ca29b15
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
17 changes: 0 additions & 17 deletions src/compas_viewer/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ def select_all(viewer: "Viewer"):
if obj.show and not obj.is_locked:
obj.is_selected = True

viewer.ui.sidebar.update()
viewer.renderer.update()


select_all_cmd = Command(title="Select All", callback=select_all)

Expand All @@ -247,9 +244,6 @@ def deselect_all(viewer: "Viewer"):
for obj in viewer.scene.objects:
obj.is_selected = False

viewer.ui.sidebar.update()
viewer.renderer.update()


deselect_all_cmd = Command(title="DeSelect All", callback=deselect_all)

Expand All @@ -275,8 +269,6 @@ def select_object(viewer: "Viewer", event: QMouseEvent):
if selected_obj:
selected_obj.is_selected = True

viewer.ui.sidebar.update()

viewer.renderer.update()


Expand All @@ -295,7 +287,6 @@ def select_multiple(viewer: "Viewer", event: QMouseEvent):
selected_obj = viewer.scene.instance_colors.get(tuple(unique_color[0])) # type: ignore
if selected_obj:
selected_obj.is_selected = True
viewer.ui.sidebar.update()

viewer.renderer.update()

Expand Down Expand Up @@ -343,8 +334,6 @@ def select_window(viewer: "Viewer", event: QMouseEvent):
obj.is_selected = True
continue

viewer.ui.sidebar.update()

viewer.renderer.update()


Expand All @@ -364,8 +353,6 @@ def deselect_object(viewer: "Viewer", event: QMouseEvent):
if selected_obj:
selected_obj.is_selected = False

viewer.ui.sidebar.update()

viewer.renderer.update()


Expand Down Expand Up @@ -394,7 +381,6 @@ def delete_selected():
if obj.is_selected:
viewer.scene.remove(obj)
del obj
viewer.renderer.update()


# =============================================================================
Expand All @@ -411,9 +397,6 @@ def clear_scene(viewer: "Viewer"):
viewer.scene.remove(obj)
del obj

viewer.ui.sidebar.update()
viewer.renderer.update()


clear_scene_cmd = Command(title="Clear Scene", callback=clear_scene)

Expand Down
2 changes: 0 additions & 2 deletions src/compas_viewer/components/sceneform.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ def on_item_clicked(self, item, column):
if self.callback and node.is_selected:
self.callback(node)

self.viewer.renderer.update()

def on_item_selection_changed(self):
for item in self.selectedItems():
if self.callback:
Expand Down
3 changes: 1 addition & 2 deletions src/compas_viewer/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ def __init__(self):
)
)

self._time = None
self.update_timer = QTimer()
self.update_timer.setSingleShot(True)
self.update_timer.timeout.connect(self.update_observers)
self.debounce_interval = 100
self.debounce_interval = 200

def add_observer(self, observer):
if observer not in self._observers:
Expand Down
28 changes: 28 additions & 0 deletions src/compas_viewer/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from compas.datastructures import Datastructure
from compas.geometry import Geometry
from compas.scene import Scene
from compas_viewer.observer import Observer

from .sceneobject import ViewerSceneObject

Expand Down Expand Up @@ -68,17 +69,28 @@ class ViewerScene(Scene):
def __init__(self, name: str = "ViewerScene", context: str = "Viewer"):
super().__init__(name=name, context=context)

# Observer
self._observer = None

# Primitive
self.objects: list[ViewerSceneObject]
# Selection
self.instance_colors: dict[tuple[int, int, int], ViewerSceneObject] = {}
self._instance_colors_generator = instance_colors_generator()

@property
<<<<<<< HEAD
def viewer(self):
from compas_viewer import Viewer

return Viewer()
=======
def observer(self):
"""Observer: The observer object for the scene."""
if self._observer is None:
self._observer = Observer()
return self._observer
>>>>>>> 45eaaab56 (clean up)

# TODO: These fixed kwargs could be moved to COMPAS core.
def add(
Expand Down Expand Up @@ -183,4 +195,20 @@ def add(
u=u,
**kwargs,
)
<<<<<<< HEAD
=======
self.observer.request_update()
>>>>>>> 45eaaab56 (clean up)
return sceneobject

def remove(self, obj: ViewerSceneObject) -> None:
"""
Remove an object from the scene.
Parameters
----------
obj : :class:`compas_viewer.scene.ViewerSceneObject`
The object to remove.
"""
super().remove(obj)
self.observer.request_update()
9 changes: 8 additions & 1 deletion src/compas_viewer/scene/sceneobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(
# Basic
super().__init__(**kwargs)

self.observer = Observer()
self._observer = None

self.show = show
self.show_points = show_points if show_points is not None else False
Expand Down Expand Up @@ -139,6 +139,13 @@ def __init__(

self._inited = False

@property
def observer(self) -> bool:
"""bool : Whether the scene is requested to be updated."""
if self._observer is None:
self._observer = Observer()
return self._observer

@property
def is_selected(self):
return self._is_selected
Expand Down

0 comments on commit ca29b15

Please sign in to comment.