Skip to content

Commit 040a902

Browse files
committed
Fix import errors in compas_rhino conduits for Rhino 8
1 parent d43a85c commit 040a902

File tree

6 files changed

+41
-34
lines changed

6 files changed

+41
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
* Fixed `RuntimeError` when using `compas_rhino.unload_modules` in CPython`.
1515
* Fixed bug in `Box.scaled` causing a `TypeError` due to incorrect parameter forwarding.
1616
* Changed argument names of `Box.scale()` to `x`, `y`, `z`, instead of `factor` and made `y` and `z` optional to keep positional arguments backwards compatible.
17+
* Fixed import errors in `compas_rhino.conduits` for Rhino 8.
1718

1819
### Removed
1920

src/compas_rhino/conduits/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import time
66
from contextlib import contextmanager
77

8-
import Rhino
9-
import scriptcontext as sc
8+
import Rhino # type: ignore
9+
import scriptcontext as sc # type: ignore
1010

1111

1212
class BaseConduit(Rhino.Display.DisplayConduit):

src/compas_rhino/conduits/faces.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from __future__ import division
33
from __future__ import print_function
44

5-
from Rhino.Geometry import Point3d
6-
from System.Drawing.Color import FromArgb
5+
import Rhino # type: ignore
6+
import System # type: ignore
77

8+
from compas.data.validators import is_sequence_of_iterable
89
from compas.itertools import iterable_like
9-
from compas.utilities import is_sequence_of_iterable
1010

1111
from .base import BaseConduit
1212

@@ -49,7 +49,7 @@ class FacesConduit(BaseConduit):
4949
5050
"""
5151

52-
default_color = FromArgb(255, 255, 255)
52+
default_color = System.Drawing.Color.FromArgb(255, 255, 255)
5353

5454
def __init__(self, vertices, faces, color=None, **kwargs):
5555
super(FacesConduit, self).__init__(**kwargs)
@@ -68,7 +68,7 @@ def color(self, color):
6868
return
6969
if not is_sequence_of_iterable(color):
7070
color = [color]
71-
color = [FromArgb(*c) for c in iterable_like(self.faces, color, self.default_color)]
71+
color = [System.Drawing.Color.FromArgb(*c) for c in iterable_like(self.faces, color, self.default_color)]
7272
self._color = color
7373

7474
def DrawForeground(self, e):
@@ -84,7 +84,7 @@ def DrawForeground(self, e):
8484
8585
"""
8686
for i, face in enumerate(self.faces):
87-
points = [Point3d(*self.vertices[key]) for key in face]
87+
points = [Rhino.Geometry.Point3d(*self.vertices[key]) for key in face]
8888
if self.color:
8989
e.Display.DrawPolygon(points, self.color[i], True)
9090
else:

src/compas_rhino/conduits/labels.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from __future__ import division
33
from __future__ import print_function
44

5-
from Rhino.Geometry import Point3d
6-
from System.Drawing.Color import FromArgb
5+
import Rhino # type: ignore
6+
import System # type: ignore
77

8+
from compas.data.validators import is_sequence_of_iterable
89
from compas.itertools import iterable_like
9-
from compas.utilities import is_sequence_of_iterable
1010

1111
from .base import BaseConduit
1212

@@ -58,8 +58,8 @@ class LabelsConduit(BaseConduit):
5858
5959
"""
6060

61-
default_color = FromArgb(0, 0, 0)
62-
default_textcolor = FromArgb(255, 255, 255)
61+
default_color = System.Drawing.Color.FromArgb(0, 0, 0)
62+
default_textcolor = System.Drawing.Color.FromArgb(255, 255, 255)
6363

6464
def __init__(self, labels, color=None, **kwargs):
6565
super(LabelsConduit, self).__init__(**kwargs)
@@ -79,7 +79,10 @@ def color(self, color):
7979
# the first item in the list should be a tuple of colors
8080
# if not, wrap the tuple
8181
color = [color]
82-
color = [(FromArgb(*bg), FromArgb(*text)) for bg, text in iterable_like(self.labels, color, (self.default_color, self.default_textcolor))]
82+
color = [
83+
(System.Drawing.Color.FromArgb(*bg), System.Drawing.Color.FromArgb(*text))
84+
for bg, text in iterable_like(self.labels, color, (self.default_color, self.default_textcolor)) # type: ignore
85+
]
8386
self._color = color
8487

8588
def DrawForeground(self, e):
@@ -97,6 +100,6 @@ def DrawForeground(self, e):
97100
for i, (pos, text) in enumerate(self.labels):
98101
if self.color:
99102
color, textcolor = self.color[i]
100-
e.Display.DrawDot(Point3d(*pos), text, color, textcolor)
103+
e.Display.DrawDot(Rhino.Geometry.Point3d(*pos), text, color, textcolor)
101104
else:
102-
e.Display.DrawDot(Point3d(*pos), text, self.default_color, self.default_textcolor)
105+
e.Display.DrawDot(Rhino.Geometry.Point3d(*pos), text, self.default_color, self.default_textcolor)

src/compas_rhino/conduits/lines.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from __future__ import division
33
from __future__ import print_function
44

5-
from Rhino.Geometry import Point3d
6-
from System.Drawing.Color import FromArgb
5+
import Rhino # type: ignore
6+
import System # type: ignore
77

8+
from compas.data.validators import is_sequence_of_iterable
89
from compas.itertools import iterable_like
9-
from compas.utilities import is_sequence_of_iterable
1010

1111
from .base import BaseConduit
1212

@@ -58,7 +58,7 @@ class LinesConduit(BaseConduit):
5858
"""
5959

6060
default_thickness = 1.0
61-
default_color = FromArgb(255, 255, 255)
61+
default_color = System.Drawing.Color.FromArgb(255, 255, 255)
6262

6363
def __init__(self, lines, thickness=None, color=None, **kwargs):
6464
super(LinesConduit, self).__init__(**kwargs)
@@ -76,7 +76,7 @@ def thickness(self):
7676
def thickness(self, thickness):
7777
thickness = thickness or self.default_thickness
7878
try:
79-
len(thickness)
79+
len(thickness) # type: ignore
8080
except TypeError:
8181
thickness = [thickness]
8282
thickness = iterable_like(self.lines, thickness, self.default_thickness)
@@ -91,7 +91,7 @@ def color(self, color):
9191
color = color or self.default_color
9292
if not is_sequence_of_iterable(color):
9393
color = [color]
94-
self._color = [FromArgb(*c) for c in iterable_like(self.lines, color, self.default_color)]
94+
self._color = [System.Drawing.Color.FromArgb(*c) for c in iterable_like(self.lines, color, self.default_color)]
9595

9696
def DrawForeground(self, e):
9797
"""Draw the lines.
@@ -105,5 +105,10 @@ def DrawForeground(self, e):
105105
None
106106
107107
"""
108-
for (start, end), color, thickness in zip(self.lines, self.color, self.thickness):
109-
e.Display.DrawLine(Point3d(*start), Point3d(*end), color, thickness)
108+
for (start, end), color, thickness in zip(self.lines, self.color, self.thickness): # type: ignore
109+
e.Display.DrawLine(
110+
Rhino.Geometry.Point3d(*start),
111+
Rhino.Geometry.Point3d(*end),
112+
color,
113+
thickness,
114+
)

src/compas_rhino/conduits/points.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
from __future__ import division
33
from __future__ import print_function
44

5-
from Rhino.Display.PointStyle import Simple
6-
from Rhino.Geometry import Point3d
7-
from System.Drawing.Color import FromArgb
5+
import Rhino # type: ignore
6+
import System # type: ignore
87

8+
from compas.data.validators import is_sequence_of_iterable
99
from compas.itertools import iterable_like
10-
from compas.utilities import color_to_rgb
11-
from compas.utilities.coercing import is_sequence_of_iterable
1210

1311
from .base import BaseConduit
1412

@@ -59,7 +57,7 @@ class PointsConduit(BaseConduit):
5957
"""
6058

6159
default_size = 3
62-
default_color = FromArgb(255, 0, 0)
60+
default_color = System.Drawing.Color.FromArgb(255, 0, 0)
6361

6462
def __init__(self, points, size=None, color=None, **kwargs):
6563
super(PointsConduit, self).__init__(**kwargs)
@@ -77,7 +75,7 @@ def size(self):
7775
def size(self, size):
7876
size = size or self.default_size
7977
try:
80-
len(size)
78+
len(size) # type: ignore
8179
except TypeError:
8280
size = [size]
8381
size = iterable_like(self.points, size, self.default_size)
@@ -92,7 +90,7 @@ def color(self, color):
9290
color = color or self.default_color
9391
if not is_sequence_of_iterable(color):
9492
color = [color]
95-
color = [FromArgb(*color_to_rgb(c)) for c in iterable_like(self.points, color, self.default_color)]
93+
color = [System.Drawing.Color.FromArgb(*c) for c in iterable_like(self.points, color, self.default_color)]
9694
self._color = color
9795

9896
def DrawForeground(self, e):
@@ -107,5 +105,5 @@ def DrawForeground(self, e):
107105
None
108106
109107
"""
110-
for xyz, size, color in zip(self.points, self.size, self.color):
111-
e.Display.DrawPoint(Point3d(*xyz), Simple, size, color)
108+
for xyz, size, color in zip(self.points, self.size, self.color): # type: ignore
109+
e.Display.DrawPoint(Rhino.Geometry.Point3d(*xyz), Rhino.Display.PointStyle.Simple, size, color)

0 commit comments

Comments
 (0)