Skip to content

Commit a8d1864

Browse files
Multimethod changes and type checking (#1969)
* Fix free func cone dispatching * Expose multidispatch via utils * Fix import * Fix formatting * Another black fix * Use a custom multidispatch implementation * Disable no impl error code * Switch Plane to the new implementation * Convert rest of geom to multidispatch * Convert even more methods/funcs and fix issues * Typo fix * Coverge tweaks * Enable typechecking of multimethods * Fix shapes * Fix sketch * Fix Workplane * Apply suggestions from code review Co-authored-by: Jeremy Wright <wrightjmf@gmail.com> * Apply suggestion * Black fix --------- Co-authored-by: adam-urbanczyk <13981538+adam-urbanczyk@users.noreply.github.com> Co-authored-by: Jeremy Wright <wrightjmf@gmail.com>
1 parent 32c4d62 commit a8d1864

10 files changed

Lines changed: 260 additions & 129 deletions

File tree

cadquery/cq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,7 +3657,7 @@ def _getFaces(self) -> List[Face]:
36573657

36583658
for el in self.objects:
36593659
if isinstance(el, Sketch):
3660-
rv.extend(el)
3660+
rv.extend(f for f in el if isinstance(f, Face))
36613661
elif isinstance(el, Face):
36623662
rv.append(el)
36633663
elif isinstance(el, Compound):
@@ -3677,7 +3677,7 @@ def _getFacesVertices(self) -> List[Union[Face, Vertex]]:
36773677

36783678
for el in self.objects:
36793679
if isinstance(el, Sketch):
3680-
rv.extend(el)
3680+
rv.extend(f for f in el if isinstance(f, Face))
36813681
elif isinstance(el, (Face, Vertex)):
36823682
rv.append(el)
36833683
elif isinstance(el, Compound):

cadquery/occ_impl/exporters/dxf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def add_shape(self, shape: Union[WorkplaneLike, Shape], layer: str = "") -> Self
155155

156156
if isinstance(shape, WorkplaneLike):
157157
plane = shape.plane
158-
shape_ = compound(*shape).transformShape(plane.fG)
158+
shape_ = compound(*shape.__iter__()).transformShape(plane.fG)
159159
else:
160160
shape_ = shape
161161

cadquery/occ_impl/geom.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
from OCP.TopLoc import TopLoc_Location
2727
from OCP.BinTools import BinTools_LocationSet
2828

29-
from multimethod import multidispatch
30-
3129
from ..types import Real
32-
from ..utils import multimethod
30+
from ..utils import multidispatch
3331

3432
TOL = 1e-2
3533

@@ -606,7 +604,7 @@ def __init__(
606604
self._setPlaneDir(xDir)
607605
self.origin = Vector(origin)
608606

609-
@__init__.register
607+
@multidispatch
610608
def __init__(
611609
self, loc: "Location",
612610
):
@@ -1031,7 +1029,7 @@ class Location(object):
10311029

10321030
wrapped: TopLoc_Location
10331031

1034-
@multimethod
1032+
@multidispatch
10351033
def __init__(self, t: VectorLike) -> None:
10361034
"""Location with translation t with respect to the original location."""
10371035

@@ -1040,7 +1038,7 @@ def __init__(self, t: VectorLike) -> None:
10401038

10411039
self.wrapped = TopLoc_Location(T)
10421040

1043-
@__init__.register
1041+
@multidispatch
10441042
def __init__(
10451043
self,
10461044
x: Real = 0,
@@ -1069,7 +1067,7 @@ def __init__(
10691067

10701068
self.wrapped = loc
10711069

1072-
@__init__.register
1070+
@multidispatch
10731071
def __init__(self, t: Plane) -> None:
10741072
"""Location corresponding to the location of the Plane t."""
10751073

@@ -1079,7 +1077,7 @@ def __init__(self, t: Plane) -> None:
10791077

10801078
self.wrapped = TopLoc_Location(T)
10811079

1082-
@__init__.register
1080+
@multidispatch
10831081
def __init__(self, t: Plane, v: VectorLike) -> None:
10841082
"""Location corresponding to the angular location of the Plane t with translation v."""
10851083

@@ -1089,19 +1087,19 @@ def __init__(self, t: Plane, v: VectorLike) -> None:
10891087

10901088
self.wrapped = TopLoc_Location(T)
10911089

1092-
@__init__.register
1090+
@multidispatch
10931091
def __init__(self, T: TopLoc_Location) -> None:
10941092
"""Location wrapping the low-level TopLoc_Location object t"""
10951093

10961094
self.wrapped = T
10971095

1098-
@__init__.register
1096+
@multidispatch
10991097
def __init__(self, T: gp_Trsf) -> None:
11001098
"""Location wrapping the low-level gp_Trsf object t"""
11011099

11021100
self.wrapped = TopLoc_Location(T)
11031101

1104-
@__init__.register
1102+
@multidispatch
11051103
def __init__(self, t: VectorLike, ax: VectorLike, angle: Real) -> None:
11061104
"""Location with translation t and rotation around ax by angle
11071105
with respect to the original location."""
@@ -1112,7 +1110,7 @@ def __init__(self, t: VectorLike, ax: VectorLike, angle: Real) -> None:
11121110

11131111
self.wrapped = TopLoc_Location(T)
11141112

1115-
@__init__.register
1113+
@multidispatch
11161114
def __init__(self, t: VectorLike, angles: Tuple[Real, Real, Real]) -> None:
11171115
"""Location with translation t and 3 rotation angles."""
11181116

0 commit comments

Comments
 (0)