Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `compas_rhino.objects`.
* Added `compas_rhino.layers`.
* Added `compas_rhino.install_with_pip`.
* Added `before_draw` pluggable to `compas.scene.Scene.draw`.
* Added `after_draw` pluggable to `compas.scene.Scene.draw`.

### Changed

* Changed `compas.tolerance.Tolerance` into singleton.
* Changed `compas_rhino.geometry.curves.nursb.RhinoNurbsCurve` to use private data API.
* Changed `compas_rhino.geometry.surfaces.nursb.RhinoNurbsSurface` to use private data API.
* Changed `compas.scene.Scene.redraw` to `draw`.
* Fixed `register_scene_objects` not called when there is a context given in kwargs of `SceneObject`.

### Removed

Expand Down
3 changes: 2 additions & 1 deletion docs/api/compas.scene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ Pluggables are functions that don't have an actual implementation, but receive a
:nosignatures:

clear
redraw
before_draw
after_draw
register_scene_objects
2 changes: 1 addition & 1 deletion docs/userguide/basics.visualisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COMPAS (data) objects can be visualised by placing them into a "scene".
>>> box = Box(1)
>>> scene = Scene()
>>> scene.add(box)
>>> scene.redraw()
>>> scene.draw()

.. When a COMPAS object is added, the scene automatically creates a corresponding scene object for the current/active visualisation context.
.. Currently, four visualisation contexts are supported: COMPAS Viewer (default), Rhino, Grasshopper, and Blender.
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/cad.blender.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ For more information on visualisation scenes, see :doc:`/userguide/basics.visual
scene = Scene()
scene.clear()
scene.add(mesh)
scene.redraw()
scene.draw()


Conversions
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/cad.grasshopper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ component on your Grasshopper canvas, paste the following script and hit `OK`.

scene = Scene()
scene.add(mesh)
a = scene.redraw()
a = scene.draw()


.. figure:: /_images/userguide/cad.grasshopper.gh_verify.jpg
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/cad.rhino.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ For more information on visualisation scenes, see :doc:`/userguide/basics.visual
scene = Scene()
scene.clear()
scene.add(mesh)
scene.redraw()
scene.draw()


Conversions
Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/cad.rhino8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ For more information on visualisation scenes, see :doc:`/userguide/basics.visual
scene = Scene()
scene.clear()
scene.add(mesh)
scene.redraw()
scene.draw()


Conversions
Expand Down
6 changes: 3 additions & 3 deletions docs/userguide/firststeps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A Simple Box

scene = Scene()
scene.add(box)
scene.redraw()
scene.draw()


Points-in-box Test
Expand All @@ -51,7 +51,7 @@ Points-in-box Test
for point in pcl:
color = Color.red() if box.contains(point) else Color.blue()
scene.add(point, color=color)
scene.redraw()
scene.draw()


Creating a Mesh From an OBJ File
Expand All @@ -67,4 +67,4 @@ Creating a Mesh From an OBJ File

scene = Scene()
scene.add(mesh)
scene.redraw()
scene.draw()
2 changes: 1 addition & 1 deletion docs/userguide/samples/point_in_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
size = 30
scene.add(point, pointcolor=color, pointsize=size)

scene.redraw()
scene.draw()
2 changes: 1 addition & 1 deletion docs/userguide/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@


scene.print_hierarchy()
scene.redraw()
scene.draw()
6 changes: 4 additions & 2 deletions src/compas/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from .volmeshobject import VolMeshObject

from .context import clear
from .context import redraw
from .context import before_draw
from .context import after_draw
from .context import register_scene_objects
from .context import get_sceneobject_cls
from .context import register
Expand Down Expand Up @@ -51,7 +52,8 @@ def register_scene_objects_base():
"SceneObjectNode",
"SceneTree",
"clear",
"redraw",
"before_draw",
"after_draw",
"register_scene_objects",
"get_sceneobject_cls",
"register",
Expand Down
49 changes: 43 additions & 6 deletions src/compas/scene/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,55 @@

@pluggable(category="drawing-utils")
def clear(guids=None):
"""Pluggable to clear the current context of the scene or a list of objects through guids.

Parameters
----------
guids : list, optional
A list of guids to clear.

Returns
-------
None
"""
raise NotImplementedError


clear.__pluggable__ = True


@pluggable(category="drawing-utils")
def redraw():
raise NotImplementedError
def before_draw():
"""Pluggable to perform operations before drawing the scene. This function is automatically called in the beginning of `compas.scene.Scene.draw()`.

Returns
-------
None

"""
pass


before_draw.__pluggable__ = True


redraw.__pluggable__ = True
@pluggable(category="drawing-utils")
def after_draw(drawn_objects):
"""Pluggable to perform operations after drawing the scene. This function is automatically called at the end of `compas.scene.Scene.draw()`.
Parameters
----------
drawn_objects : list
A list of objects that were drawn.

Returns
-------
None

"""
pass


after_draw.__pluggable__ = True


@pluggable(category="factories", selector="collect_all")
Expand Down Expand Up @@ -82,9 +119,6 @@ def detect_current_context():

"""

if not ITEM_SCENEOBJECT:
register_scene_objects()

if is_viewer_open():
return "Viewer"
if compas.is_grasshopper():
Expand Down Expand Up @@ -126,6 +160,9 @@ def _get_sceneobject_cls(data, **kwargs):


def get_sceneobject_cls(item, **kwargs):
if not ITEM_SCENEOBJECT:
register_scene_objects()

if item is None:
raise ValueError(
"Cannot create a scene object for None. Please ensure you pass a instance of a supported class."
Expand Down
14 changes: 8 additions & 6 deletions src/compas/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from compas.datastructures import TreeNode

from .context import clear
from .context import redraw
from .context import before_draw
from .context import after_draw
from .context import detect_current_context
from .sceneobject import SceneObject

Expand Down Expand Up @@ -199,7 +200,7 @@ class Scene(Data):
>>> scene = Scene()
>>> box = Box.from_width_height_depth(1, 1, 1)
>>> scene.add(box)
>>> scene.redraw()
>>> scene.draw()

"""

Expand Down Expand Up @@ -287,8 +288,10 @@ def clear_objects(self):
sceneobject._guids = None
clear(guids=guids)

def redraw(self):
"""Redraw the scene."""
def draw(self):
"""Draw the scene."""

before_draw()

if not self.context:
raise ValueError("No context detected.")
Expand All @@ -299,8 +302,7 @@ def redraw(self):
for sceneobject in self.objects:
drawn_objects += sceneobject.draw()

if drawn_objects:
redraw()
after_draw(drawn_objects)

return drawn_objects

Expand Down
4 changes: 2 additions & 2 deletions src/compas_blender/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def clear_blender(guids=None):
compas_blender.clear(guids=guids)


@plugin(category="drawing-utils", pluggable_name="redraw", requires=["bpy"])
def redraw_blender():
@plugin(category="drawing-utils", pluggable_name="after_draw", requires=["bpy"])
def after_draw_blender(drawn_objects):
compas_blender.redraw()


Expand Down
5 changes: 0 additions & 5 deletions src/compas_ghpython/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ def clear_GH(guids=None):
pass


@plugin(category="drawing-utils", pluggable_name="redraw", requires=["Grasshopper"])
def redraw_GH():
pass


@plugin(category="factories", requires=["Rhino"])
def register_scene_objects():
register(Box, BoxObject, context="Grasshopper")
Expand Down
2 changes: 1 addition & 1 deletion src/compas_rhino/conversions/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def surface_to_compas_mesh(surface, cls=None, facefilter=None, cleanup=False):

>>> scene = Scene()
>>> scene.add(mesh, layer="Blocks")
>>> scene.redraw()
>>> scene.draw()

"""
if not surface.HasBrepForm:
Expand Down
4 changes: 2 additions & 2 deletions src/compas_rhino/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def clear_rhino(guids=None):
compas_rhino.clear(guids=guids)


@plugin(category="drawing-utils", pluggable_name="redraw", requires=["Rhino"])
def redraw_rhino():
@plugin(category="drawing-utils", pluggable_name="after_draw", requires=["Rhino"])
def after_draw_rhino(drawn_objects):
compas_rhino.redraw()


Expand Down
12 changes: 6 additions & 6 deletions src/compas_rhino/scene/graphobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def clear(self):
None

"""
guids = compas_rhino.get_objects(name="{}.*".format(self.graph.name)) # type: ignore
compas_rhino.delete_objects(guids, purge=True)
guids = compas_rhino.objects.get_objects(name="{}.*".format(self.graph.name)) # type: ignore
compas_rhino.objects.delete_objects(guids, purge=True)

def clear_nodes(self):
"""Delete all nodes drawn by this scene object.
Expand All @@ -56,8 +56,8 @@ def clear_nodes(self):
None

"""
guids = compas_rhino.get_objects(name="{}.node.*".format(self.graph.name)) # type: ignore
compas_rhino.delete_objects(guids, purge=True)
guids = compas_rhino.objects.get_objects(name="{}.node.*".format(self.graph.name)) # type: ignore
compas_rhino.objects.delete_objects(guids, purge=True)

def clear_edges(self):
"""Delete all edges drawn by this scene object.
Expand All @@ -67,8 +67,8 @@ def clear_edges(self):
None

"""
guids = compas_rhino.get_objects(name="{}.edge.*".format(self.graph.name)) # type: ignore
compas_rhino.delete_objects(guids, purge=True)
guids = compas_rhino.objects.get_objects(name="{}.edge.*".format(self.graph.name)) # type: ignore
compas_rhino.objects.delete_objects(guids, purge=True)

# ==========================================================================
# draw
Expand Down