Skip to content

Commit

Permalink
Merge pull request #1200 from compas-dev/ellipse-artists
Browse files Browse the repository at this point in the history
Add ellipse artists for rhino/gh
  • Loading branch information
gonzalocasas authored Oct 9, 2023
2 parents 0d50b15 + 4a7c982 commit 64c435b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `EllipseArtist` to `compas_rhino` and `compas_ghpython`.

### Changed

* Changed `Network.is_planar` to rely on `NetworkX` instead `planarity` for planarity checking.
Expand Down
1 change: 1 addition & 0 deletions docs/reference/compas_ghpython.artists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Classes
ConeArtist
CurveArtist
CylinderArtist
EllipseArtist
FrameArtist
LineArtist
MeshArtist
Expand Down
1 change: 1 addition & 0 deletions docs/reference/compas_rhino.artists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Classes
ConeArtist
CurveArtist
CylinderArtist
EllipseArtist
FrameArtist
LineArtist
MeshArtist
Expand Down
4 changes: 4 additions & 0 deletions src/compas_ghpython/artists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from compas.geometry import Cone
from compas.geometry import Curve
from compas.geometry import Cylinder
from compas.geometry import Ellipse
from compas.geometry import Frame
from compas.geometry import Line
from compas.geometry import Point
Expand All @@ -32,6 +33,7 @@
from .coneartist import ConeArtist
from .curveartist import CurveArtist
from .cylinderartist import CylinderArtist
from .ellipseartist import EllipseArtist
from .frameartist import FrameArtist
from .lineartist import LineArtist
from .meshartist import MeshArtist
Expand All @@ -56,6 +58,7 @@ def register_artists():
Artist.register(Cone, ConeArtist, context="Grasshopper")
Artist.register(Curve, CurveArtist, context="Grasshopper")
Artist.register(Cylinder, CylinderArtist, context="Grasshopper")
Artist.register(Ellipse, EllipseArtist, context="Grasshopper")
Artist.register(Frame, FrameArtist, context="Grasshopper")
Artist.register(Line, LineArtist, context="Grasshopper")
Artist.register(Mesh, MeshArtist, context="Grasshopper")
Expand All @@ -81,6 +84,7 @@ def register_artists():
"ConeArtist",
"CurveArtist",
"CylinderArtist",
"EllipseArtist",
"FrameArtist",
"LineArtist",
"MeshArtist",
Expand Down
40 changes: 40 additions & 0 deletions src/compas_ghpython/artists/ellipseartist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

from compas_rhino import conversions

from compas.artists import GeometryArtist
from .artist import GHArtist


class EllipseArtist(GHArtist, GeometryArtist):
"""Artist for drawing ellipses.
Parameters
----------
ellipse : :class:`~compas.geometry.Ellipse`
A COMPAS ellipse.
**kwargs : dict, optional
Additional keyword arguments.
"""

def __init__(self, ellipse, **kwargs):
super(EllipseArtist, self).__init__(geometry=ellipse, **kwargs)

def draw(self):
"""Draw the ellipse.
Returns
-------
:rhino:`Rhino.Geometry.Ellipse`
"""
ellipse = conversions.ellipse_to_rhino(self.geometry)

if self.transformation:
transformation = conversions.transformation_to_rhino(self.transformation)
ellipse.Transform(transformation)

return ellipse
6 changes: 6 additions & 0 deletions src/compas_rhino/artists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from compas.artists import Artist

from compas.geometry import Circle
from compas.geometry import Ellipse
from compas.geometry import Frame
from compas.geometry import Line
from compas.geometry import Plane
Expand Down Expand Up @@ -32,20 +33,23 @@

from .artist import RhinoArtist
from .circleartist import CircleArtist
from .ellipseartist import EllipseArtist
from .frameartist import FrameArtist
from .lineartist import LineArtist
from .planeartist import PlaneArtist
from .pointartist import PointArtist
from .polygonartist import PolygonArtist
from .polylineartist import PolylineArtist
from .vectorartist import VectorArtist

from .boxartist import BoxArtist
from .capsuleartist import CapsuleArtist
from .coneartist import ConeArtist
from .cylinderartist import CylinderArtist
from .polyhedronartist import PolyhedronArtist
from .sphereartist import SphereArtist
from .torusartist import TorusArtist

from .meshartist import MeshArtist
from .networkartist import NetworkArtist
from .volmeshartist import VolMeshArtist
Expand All @@ -68,6 +72,7 @@ def redraw_rhino():
@plugin(category="factories", requires=["Rhino"])
def register_artists():
Artist.register(Circle, CircleArtist, context="Rhino")
Artist.register(Ellipse, EllipseArtist, context="Rhino")
Artist.register(Frame, FrameArtist, context="Rhino")
Artist.register(Line, LineArtist, context="Rhino")
Artist.register(Plane, PlaneArtist, context="Rhino")
Expand All @@ -94,6 +99,7 @@ def register_artists():
__all__ = [
"RhinoArtist",
"CircleArtist",
"EllipseArtist",
"FrameArtist",
"LineArtist",
"PlaneArtist",
Expand Down
53 changes: 53 additions & 0 deletions src/compas_rhino/artists/ellipseartist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import scriptcontext as sc # type: ignore

from compas.artists import GeometryArtist
from compas.colors import Color
from compas_rhino.conversions import ellipse_to_rhino

from compas_rhino.conversions import transformation_to_rhino
from .artist import RhinoArtist
from ._helpers import attributes


class EllipseArtist(RhinoArtist, GeometryArtist):
"""Artist for drawing ellipses.
Parameters
----------
ellipse : :class:`~compas.geometry.Ellipse`
A COMPAS ellipse.
**kwargs : dict, optional
Additional keyword arguments.
"""

def __init__(self, ellipse, **kwargs):
super(EllipseArtist, self).__init__(geometry=ellipse, **kwargs)

def draw(self, color=None):
"""Draw the ellipse.
Parameters
----------
color : rgb1 | rgb255 | :class:`~compas.colors.Color`, optional
The RGB color of the ellipse.
Returns
-------
System.Guid
The GUID of the created Rhino object.
"""
color = Color.coerce(color) or self.color
attr = attributes(name=self.geometry.name, color=color, layer=self.layer)

geometry = ellipse_to_rhino(self.geometry)

if self.transformation:
geometry.Transform(transformation_to_rhino(self.transformation))

return sc.doc.Objects.AddEllipse(geometry, attr)

0 comments on commit 64c435b

Please sign in to comment.