Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item as kwarg #177

Merged
merged 7 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed `load_scene` action bug.
* Changed base of shapes to `compas_viewer.scene.ShapeObject`.
* Changed `FrameObject` to something with just 3 axes.
* Restructured `SceneObjects` to accepct `item` as kwargs.
* Fixed `compas_viewer.components.slider` step attribute.

### Removed
Expand Down
2 changes: 1 addition & 1 deletion src/compas_viewer/commands.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pathlib
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
Expand All @@ -9,7 +10,6 @@
from numpy import array
from numpy import unique
from numpy.linalg import norm
import pathlib
from PySide6.QtCore import QEvent
from PySide6.QtCore import Qt
from PySide6.QtGui import QMouseEvent
Expand Down
24 changes: 6 additions & 18 deletions src/compas_viewer/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@
from .tagobject import TagObject, Tag
from .frameobject import FrameObject
from .circleobject import CircleObject
from .boxobject import BoxObject
from .torusobject import TorusObject
from .polylineobject import PolylineObject
from .polygonobject import PolygonObject
from .sphereobject import SphereObject
from .planeobject import PlaneObject
from .cylinderobject import CylinderObject
from .ellipseobject import EllipseObject
from .coneobject import ConeObject
from .capsuleobject import CapsuleObject
from .polyhedronobject import PolyhedronObject
from .geometryobject import GeometryObject
from .shapeobject import ShapeObject
Expand Down Expand Up @@ -81,16 +75,16 @@ def register_scene_objects():
register(Frame, FrameObject, context="Viewer")
register(Vector, VectorObject, context="Viewer")
register(Circle, CircleObject, context="Viewer")
register(Box, BoxObject, context="Viewer")
register(Box, ShapeObject, context="Viewer")
register(Polyline, PolylineObject, context="Viewer")
register(Torus, TorusObject, context="Viewer")
register(Torus, ShapeObject, context="Viewer")
register(Polygon, PolygonObject, context="Viewer")
register(Sphere, SphereObject, context="Viewer")
register(Sphere, ShapeObject, context="Viewer")
register(Plane, PlaneObject, context="Viewer")
register(Cylinder, CylinderObject, context="Viewer")
register(Cylinder, ShapeObject, context="Viewer")
register(Ellipse, EllipseObject, context="Viewer")
register(Cone, ConeObject, context="Viewer")
register(Capsule, CapsuleObject, context="Viewer")
register(Cone, ShapeObject, context="Viewer")
register(Capsule, ShapeObject, context="Viewer")
register(Polyhedron, PolyhedronObject, context="Viewer")
register(list, GroupObject, context="Viewer")
register(Collection, CollectionObject, context="Viewer")
Expand Down Expand Up @@ -130,23 +124,17 @@ def register_scene_objects():
"Polyline",
"PolylineObject",
"Box",
"BoxObject",
"Torus",
"TorusObject",
"Polygon",
"PolygonObject",
"Sphere",
"SphereObject",
"Plane",
"PlaneObject",
"Cylinder",
"CylinderObject",
"Ellipse",
"EllipseObject",
"Cone",
"ConeObject",
"Capsule",
"CapsuleObject",
"NurbsSurface",
"NurbsSurfaceObject",
"GeometryObject",
Expand Down
16 changes: 0 additions & 16 deletions src/compas_viewer/scene/boxobject.py

This file was deleted.

7 changes: 2 additions & 5 deletions src/compas_viewer/scene/brepobject.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Optional

from compas_occ.brep import OCCBrep

from compas.datastructures import Mesh
from compas.geometry import Line
from compas.geometry import Point
Expand All @@ -26,9 +24,8 @@ class BRepObject(ViewerGeometryObject, GeometryObject):
:class:`compas_occ.brep.Brep`
"""

def __init__(self, brep: OCCBrep, **kwargs):
super().__init__(geometry=brep, **kwargs)
self.geometry: OCCBrep
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._viewmesh, self._boundaries = self.geometry.to_tesselation(TOL.lineardeflection)

@property
Expand Down
8 changes: 5 additions & 3 deletions src/compas_viewer/scene/bufferobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ class BufferObject(SceneObject, Base):

def __init__(
self,
buffergeometry: BufferGeometry,
show_points: Optional[bool] = None,
show_lines: Optional[bool] = None,
show_faces: Optional[bool] = None,
Expand All @@ -198,8 +197,7 @@ def __init__(
is_visiable: Optional[bool] = None,
**kwargs,
):
super().__init__(item=buffergeometry, **kwargs)
self.buffergeometry = buffergeometry
super().__init__(**kwargs)

self.show_points = True if show_points is None else show_points
self.show_lines = True if show_lines is None else show_lines
Expand All @@ -214,6 +212,10 @@ def __init__(
self.background = False
self._matrix_buffer = None

@property
def buffergeometry(self) -> BufferGeometry:
return self.item

def init(self):
"""Initialize the object"""
self.instance_color = Color.from_rgb255(*next(self.scene._instance_colors_generator))
Expand Down
16 changes: 0 additions & 16 deletions src/compas_viewer/scene/capsuleobject.py

This file was deleted.

12 changes: 4 additions & 8 deletions src/compas_viewer/scene/circleobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@


class CircleObject(ViewerGeometryObject, GeometryObject):
"""Viewer scene object for displaying COMPAS Circle geometry.
"""Viewer scene object for displaying COMPAS Circle geometry."""

See Also
--------
:class:`compas.geometry.Circle`
"""
geometry: Circle

def __init__(self, circle: Circle, **kwargs):
super().__init__(geometry=circle, **kwargs)
self.geometry: Circle
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.show_lines = True

@property
Expand Down
12 changes: 8 additions & 4 deletions src/compas_viewer/scene/collectionobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ def __data__(self):
class CollectionObject(ViewerSceneObject, GeometryObject):
"""Viewer scene object for displaying a collection of COMPAS geometries."""

def __init__(self, collection: Collection, **kwargs):
self.collection = collection
super().__init__(geometry=self.collection, **kwargs)
self.objects = [ViewerSceneObject(item, **kwargs) for item in self.collection.items]
def __init__(self, **kwargs):
super().__init__(**kwargs)
kwargs.pop("item")
Copy link
Member

Choose a reason for hiding this comment

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

what does this do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was to remove item from kwargs so in next line item is not given twice which will trigger error.

Copy link
Member

Choose a reason for hiding this comment

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

just put item as a keyword argument in the first init

self.objects = [ViewerSceneObject(item=item, **kwargs) for item in self.collection.items]

@property
def collection(self) -> Collection:
return self.item

def _read_points_data(self) -> ShaderDataType:
positions = []
Expand Down
16 changes: 0 additions & 16 deletions src/compas_viewer/scene/coneobject.py

This file was deleted.

16 changes: 0 additions & 16 deletions src/compas_viewer/scene/cylinderobject.py

This file was deleted.

24 changes: 6 additions & 18 deletions src/compas_viewer/scene/ellipseobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,12 @@


class EllipseObject(ViewerGeometryObject, GeometryObject):
"""Viewer scene object for displaying COMPAS Ellipse geometry.

Parameters
----------
ellipse : :class:`compas.geometry.Ellipse`
A COMPAS ellipse geometry.
**kwargs : dict, optional
Additional options for the :class:`compas_viewer.scene.ViewerSceneObject`
and :class:`compas.scene.GeometryObject`.

See Also
--------
:class:`compas.geometry.Ellipse`
"""

def __init__(self, ellipse: Ellipse, **kwargs):
super().__init__(geometry=ellipse, **kwargs)
self.geometry: Ellipse
"""Viewer scene object for displaying COMPAS Ellipse geometry."""

geometry: Ellipse

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.show_lines = True

@property
Expand Down
4 changes: 1 addition & 3 deletions src/compas_viewer/scene/frameobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ class FrameObject(ViewerSceneObject):

def __init__(
self,
frame: Frame,
size: Optional[float] = 1,
**kwargs,
):
super().__init__(item=frame, **kwargs)
self.frame = frame
super().__init__(**kwargs)
self.size = size

def _read_lines_data(self) -> ShaderDataType:
Expand Down
5 changes: 1 addition & 4 deletions src/compas_viewer/scene/geometryobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from compas.colors import Color
from compas.datastructures import Mesh
from compas.geometry import Geometry
from compas.geometry import Line
from compas.geometry import Point
from compas.itertools import flatten
Expand Down Expand Up @@ -60,13 +59,11 @@ class GeometryObject(ViewerSceneObject, BaseGeometryObject):

def __init__(
self,
geometry: Geometry,
u: Optional[int] = 16,
v: Optional[int] = 16,
**kwargs,
):
super().__init__(geometry=geometry, **kwargs)
self.geometry: Geometry
super().__init__(**kwargs)
self.u = u
self.v = v

Expand Down
20 changes: 2 additions & 18 deletions src/compas_viewer/scene/graphobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,9 @@


class GraphObject(ViewerSceneObject, BaseGraphObject):
"""Viewer scene object for displaying COMPAS Graph data.
"""Viewer scene object for displaying COMPAS Graph data."""
Copy link
Member

Choose a reason for hiding this comment

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

why not add the type of graph



Parameters
----------
graph : :class:`compas.datastructures.Graph`
The graph data structure.
**kwargs : dict, optional
Additional options for the :class:`compas_viewer.scene.ViewerSceneObject`.

See Also
--------
:class:`compas.datastructures.Graph`

"""

def __init__(self, graph: Graph, **kwargs):
super(GraphObject, self).__init__(graph=graph, **kwargs)
self.graph: Graph
graph: Graph

def _read_points_data(self) -> ShaderDataType:
positions = []
Expand Down
10 changes: 7 additions & 3 deletions src/compas_viewer/scene/groupobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def __data__(self):
class GroupObject(SceneObject):
"""A group of scene objects."""

def __init__(self, items, **kwargs):
super().__init__(Group(items), **kwargs)
def __init__(self, item=None, **kwargs):
super().__init__(item=Group(item), **kwargs)
self.show = True
self.is_selected = False
self.is_locked = False
self.opacity = 1.0
self.bounding_box = None

for item in items:
for item in self.items:
if isinstance(item, (Data, list)):
self.add(item, **kwargs)
elif isinstance(item, tuple) and len(item) == 2 and isinstance(item[0], (Data, list)):
Expand All @@ -37,6 +37,10 @@ def __init__(self, items, **kwargs):
print(item)
raise TypeError("Group items must be of type `Data` or a tuple of (`Data`, kwargs).")

@property
def items(self):
return self.item.items

def init(self, *args, **kwargs):
pass

Expand Down
12 changes: 4 additions & 8 deletions src/compas_viewer/scene/lineobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@


class LineObject(ViewerGeometryObject, GeometryObject):
"""Viewer scene object for displaying COMPAS Line geometry.
"""Viewer scene object for displaying COMPAS Line geometry."""

See Also
--------
:class:`compas.geometry.Line`
"""
geometry: Line

def __init__(self, line: Line, **kwargs):
super().__init__(geometry=line, **kwargs)
self.geometry: Line
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.show_lines = True

@property
Expand Down
Loading
Loading