Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #176 from ZacZhangzhuo/zoom-selected
Browse files Browse the repository at this point in the history
Zoom selected enhancement
  • Loading branch information
Licini authored Oct 6, 2023
2 parents b7c832a + 8bfd9b3 commit 8bdd5c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `absolute_height` option to the text object.
* Added `absolute_height` option to the `TextObject`.
* Added `font` option to `TextObject`.
* Multi-cursor visual effects.
* Added `F` key for focusing the selected objects. If no object is selected, it will focus the whole scene geometries.

### Changed

Expand Down
5 changes: 4 additions & 1 deletion src/compas_view2/objects/bufferobject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from compas.utilities import flatten
from compas.geometry import transform_points_numpy

from compas_view2.gl import make_index_buffer
from compas_view2.gl import make_vertex_buffer
Expand Down Expand Up @@ -134,7 +135,9 @@ def _update_bounding_box(self, positions=None):
return

positions = np.array(positions)
self._bounding_box = np.array([positions.min(axis=0), positions.max(axis=0)])
self._bounding_box = transform_points_numpy(
np.array([positions.min(axis=0), positions.max(axis=0)]), self._transformation
)
self._bounding_box_center = np.average(self.bounding_box, axis=0)

def draw(self, shader, wireframe=False, is_lighted=False):
Expand Down
2 changes: 1 addition & 1 deletion src/compas_view2/scene/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def zoom_extents(self, objects: List[Object] = None):
if not obj.is_visible:
continue

if obj.bounding_box is None and hasattr(obj, "_update_bounding_box"):
if hasattr(obj, "_update_bounding_box"):
obj._update_bounding_box()

if obj.bounding_box is not None:
Expand Down
11 changes: 10 additions & 1 deletion src/compas_view2/views/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
self.mouse = Mouse()
self.grid = GridObject(1, 10, 10)
self.objects = {}
self.keys = {"shift": False, "control": False}
self.keys = {"shift": False, "control": False, "f": False}
self._frames = 0
self._now = time.time()

Expand Down Expand Up @@ -284,6 +284,13 @@ def keyPressEvent(self, event):
if key == QtCore.Qt.Key_Control:
self.app.selector.mode = "deselect"
self.keys["control"] = True
if key == QtCore.Qt.Key_F:
self.keys["f"] = True
if self.app.selector.selected:
self.camera.zoom_extents(self.app.selector.selected)
else:
self.camera.zoom_extents(self.objects)
self.update()

def keyReleaseEvent(self, event):
key = event.key()
Expand All @@ -293,3 +300,5 @@ def keyReleaseEvent(self, event):
if key == QtCore.Qt.Key_Control:
self.app.selector.mode = self.app.selector.overwrite_mode or "single"
self.keys["control"] = False
if key == QtCore.Qt.Key_F:
self.keys["f"] = False

0 comments on commit 8bdd5c6

Please sign in to comment.