Skip to content

Commit

Permalink
Merge pull request #170 from compas-dev/feature/obj_info
Browse files Browse the repository at this point in the history
obj info
  • Loading branch information
tomvanmele authored Jun 18, 2024
2 parents 4380e59 + 396dbbc commit 12990c8
Show file tree
Hide file tree
Showing 17 changed files with 811 additions and 211 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `compas_viewer.commands.capture_view` and corresponding command.
* Added default colors to `MeshObject`.
* Added default colors to `GeometryObject`.
* Added `object_info_cmd` for `compas_viewer.commends`.
* Added `gridmode` to `GridObject`.

### Changed
Expand Down
2 changes: 1 addition & 1 deletion scripts/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
viewer = Viewer(show_grid=True)

mesh = Mesh.from_off(compas.get("tubemesh.off"))
obj = viewer.scene.add(mesh, show_points=True, facecolor=Color.blue(), linecolor=Color.red(), pointcolor=Color.green())
obj = viewer.scene.add(mesh, show_points=True)

N = 10
M = 10
Expand Down
19 changes: 18 additions & 1 deletion src/compas_viewer/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import compas
from compas.scene import Scene
from compas_viewer.components import CameraSettingsDialog
from compas_viewer.components.camerasetting import CameraSettingsDialog
from compas_viewer.components.objectsetting import ObjectSettingDialog

if TYPE_CHECKING:
from compas_viewer import Viewer
Expand Down Expand Up @@ -460,3 +461,19 @@ def load_data():


load_data_cmd = Command(title="Load Data", callback=lambda: print("load data"))


# =============================================================================
# =============================================================================
# =============================================================================
# Info
# =============================================================================
# =============================================================================
# =============================================================================


def obj_settings(viewer: "Viewer"):
ObjectSettingDialog().exec()


obj_settings_cmd = Command(title="Object Settings", callback=obj_settings)
4 changes: 3 additions & 1 deletion src/compas_viewer/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .button import Button
from .combobox import ComboBox
from .combobox import ViewModeAction
from .dialog import CameraSettingsDialog
from .camerasetting import CameraSettingsDialog
from .objectsetting import ObjectSettingDialog
from .slider import Slider
from .treeform import Treeform
from .sceneform import Sceneform
Expand All @@ -10,6 +11,7 @@
"Button",
"ComboBox",
"CameraSettingsDialog",
"ObjectSettingDialog",
"Renderer",
"Slider",
"Treeform",
Expand Down
81 changes: 81 additions & 0 deletions src/compas_viewer/components/camerasetting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from PySide6.QtWidgets import QDialog
from PySide6.QtWidgets import QPushButton
from PySide6.QtWidgets import QVBoxLayout

from compas_viewer.base import Base
from compas_viewer.components.layout import base_layout


class CameraSettingsDialog(QDialog, Base):
"""
A dialog for displaying and updating camera settings in Qt applications.
This dialog allows users to modify the camera's target and position and
applies these changes dynamically.
Attributes
----------
layout : QVBoxLayout
The layout of the dialog.
spin_boxes : dict
Dictionary containing spin boxes for adjusting camera settings.
update_button : QPushButton
Button to apply changes to the camera settings.
camera : Camera
The camera object from the viewer's renderer.
Methods
-------
update()
Updates the camera's target and position and closes the dialog.
Example
-------
>>> dialog = CameraSettingsDialog()
>>> dialog.exec()
"""

def __init__(self) -> None:
super().__init__()
self.setWindowTitle("Camera Settings")

self.layout = QVBoxLayout(self)
self.camera = self.viewer.renderer.camera
items = [
{
"title": "Camera_Target",
"items": [
{"type": "double_edit", "title": "X", "value": self.camera.target.x, "min_val": None, "max_val": None},
{"type": "double_edit", "title": "Y", "value": self.camera.target.y, "min_val": None, "max_val": None},
{"type": "double_edit", "title": "Z", "value": self.camera.target.z, "min_val": None, "max_val": None},
],
},
{
"title": "Camera_Position",
"items": [
{"type": "double_edit", "title": "X", "value": self.camera.position.x, "min_val": None, "max_val": None},
{"type": "double_edit", "title": "Y", "value": self.camera.position.y, "min_val": None, "max_val": None},
{"type": "double_edit", "title": "Z", "value": self.camera.position.z, "min_val": None, "max_val": None},
],
},
]

camera_setting_layout, self.spin_boxes = base_layout(items)

self.layout.addLayout(camera_setting_layout)

self.update_button = QPushButton("Update Camera", self)
self.update_button.clicked.connect(self.update)
self.layout.addWidget(self.update_button)

def update(self) -> None:
self.viewer.renderer.camera.target.set(
self.spin_boxes["Camera_Target_X"].spinbox.value(),
self.spin_boxes["Camera_Target_Y"].spinbox.value(),
self.spin_boxes["Camera_Target_Z"].spinbox.value(),
)
self.viewer.renderer.camera.position.set(
self.spin_boxes["Camera_Position_X"].spinbox.value(),
self.spin_boxes["Camera_Position_Y"].spinbox.value(),
self.spin_boxes["Camera_Position_Z"].spinbox.value(),
)
self.accept()
Loading

0 comments on commit 12990c8

Please sign in to comment.