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 4 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.

### 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.

4 changes: 2 additions & 2 deletions src/compas_viewer/scene/circleobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class CircleObject(ViewerGeometryObject, GeometryObject):
:class:`compas.geometry.Circle`
"""

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

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.

21 changes: 4 additions & 17 deletions src/compas_viewer/scene/ellipseobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,10 @@


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)
"""Viewer scene object for displaying COMPAS Ellipse geometry."""

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

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
21 changes: 1 addition & 20 deletions src/compas_viewer/scene/graphobject.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
from compas.datastructures import Graph
from compas.scene import GraphObject as BaseGraphObject

from .sceneobject import ShaderDataType
from .sceneobject import ViewerSceneObject


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


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
"""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

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

def __init__(self, items, **kwargs):
super().__init__(Group(items), **kwargs)
def __init__(self, **kwargs):
items = kwargs.pop("item", [])
Licini marked this conversation as resolved.
Show resolved Hide resolved
group = Group(items)
super().__init__(item=group, **kwargs)
self.show = True
self.is_selected = False
self.is_locked = False
Expand Down
4 changes: 2 additions & 2 deletions src/compas_viewer/scene/lineobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class LineObject(ViewerGeometryObject, GeometryObject):
:class:`compas.geometry.Line`
"""

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

Expand Down
6 changes: 1 addition & 5 deletions src/compas_viewer/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Union

from compas.colors import Color
from compas.datastructures import Mesh
from compas.geometry import centroid_points
from compas.geometry import is_coplanar
from compas.itertools import pairwise
Expand Down Expand Up @@ -57,7 +56,6 @@ class MeshObject(ViewerSceneObject, BaseMeshObject):

def __init__(
self,
mesh: Mesh,
show_points: Optional[bool] = None,
show_lines: Optional[bool] = None,
pointsize: Optional[float] = None,
Expand All @@ -66,9 +64,7 @@ def __init__(
use_vertexcolors: Optional[bool] = None,
**kwargs,
):
super().__init__(mesh=mesh, **kwargs)

self.mesh: Mesh
super().__init__(**kwargs)
Licini marked this conversation as resolved.
Show resolved Hide resolved

self.show_points = show_points if show_points is not None else False
self.show_lines = show_lines if show_lines is not None else True
Expand Down
11 changes: 3 additions & 8 deletions src/compas_viewer/scene/nurbscurveobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@


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

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

def __init__(self, curve: NurbsCurve, **kwargs):
super().__init__(geometry=curve, **kwargs)
def __init__(self, **kwargs):
super().__init__(**kwargs)
Licini marked this conversation as resolved.
Show resolved Hide resolved
self.geometry: NurbsCurve

@property
Expand Down
Loading
Loading