Skip to content

Commit 957b303

Browse files
committed
backward compatibility for artist customisation
1 parent 54fcac9 commit 957b303

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/compas/artists/artist.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ class Artist(object):
3030
def __new__(cls, *args, **kwargs):
3131
return new_artist(cls, *args, **kwargs)
3232

33+
@staticmethod
34+
def build(item, **kwargs):
35+
"""Build an artist corresponding to the item type.
36+
37+
Parameters
38+
----------
39+
kwargs : dict, optional
40+
The keyword arguments (kwargs) collected in a dict.
41+
For relevant options, see the parameter lists of the matching artist type.
42+
43+
Returns
44+
-------
45+
:class:`compas.artists.Artist`
46+
An artist of the type matching the provided item according to the item-artist map ``~Artist.ITEM_ARTIST``.
47+
The map is created by registering item-artist type pairs using ``~Artist.register``.
48+
"""
49+
artist_type = Artist.ITEM_ARTIST[type(item)]
50+
artist = artist_type(item, **kwargs)
51+
return artist
52+
53+
@staticmethod
54+
def build_as(item, artist_type, **kwargs):
55+
artist = artist_type(item, **kwargs)
56+
return artist
57+
3358
@staticmethod
3459
def clear():
3560
return clear()

src/compas_rhino/artists/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
from .volmeshartist import VolMeshArtist
126126
from .robotmodelartist import RobotModelArtist
127127

128+
BaseArtist = RhinoArtist
129+
128130
ShapeArtist.default_color = (255, 255, 255)
129131

130132
MeshArtist.default_color = (0, 0, 0)
@@ -213,6 +215,7 @@ def new_artist_rhino(cls, *args, **kwargs):
213215

214216

215217
__all__ = [
218+
'BaseArtist',
216219
'RhinoArtist',
217220
'CircleArtist',
218221
'FrameArtist',

0 commit comments

Comments
 (0)