Skip to content

Commit

Permalink
Merge pull request #176 from fusion-energy/updates_for_cq_2.2
Browse files Browse the repository at this point in the history
Updates for cq 2.2
  • Loading branch information
shimwell authored Jan 31, 2022
2 parents 6b56652 + 92c9dcc commit f992bf2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import numpy as np

from paramak import ExtrudeStraightShape
from paramak.utils import calculate_wedge_cut, rotate
from paramak.utils import calculate_wedge_cut, rotate, patch_workplane

patch_workplane()


class ToroidalFieldCoilCoatHanger(ExtrudeStraightShape):
Expand Down Expand Up @@ -222,7 +224,7 @@ def create_solid(self):

self.wire = wire

solid = wire.extrude(distance=-self.distance / 2.0, both=True)
solid = wire.extrude(until=-self.distance / 2.0, both=True)

solid = self.rotate_solid(solid)

Expand All @@ -233,7 +235,7 @@ def create_solid(self):
inner_leg_solid = cq.Workplane(self.workplane)
inner_leg_solid = inner_leg_solid.polyline(self.inner_leg_connection_points)
inner_leg_solid = inner_leg_solid.close().extrude(
distance=-self.distance / 2.0, both=True
until=-self.distance / 2.0, both=True
)

inner_leg_solid = self.rotate_solid(inner_leg_solid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import numpy as np

from paramak import ExtrudeStraightShape
from paramak.utils import calculate_wedge_cut
from paramak.utils import calculate_wedge_cut, patch_workplane

patch_workplane()


class ToroidalFieldCoilRectangle(ExtrudeStraightShape):
Expand Down Expand Up @@ -129,7 +131,7 @@ def create_solid(self):

self.wire = wire

solid = wire.extrude(distance=-self.distance / 2.0, both=True)
solid = wire.extrude(until=-self.distance / 2.0, both=True)

solid = self.rotate_solid(solid)

Expand All @@ -140,7 +142,7 @@ def create_solid(self):
inner_leg_solid = cq.Workplane(self.workplane)
inner_leg_solid = inner_leg_solid.polyline(self.inner_leg_connection_points)
inner_leg_solid = inner_leg_solid.close().extrude(
distance=-self.distance / 2.0, both=True
until=-self.distance / 2.0, both=True
)

inner_leg_solid = self.rotate_solid(inner_leg_solid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import numpy as np

from paramak.parametric_shapes.extruded_mixed_shape import ExtrudeMixedShape
from paramak.utils import calculate_wedge_cut
from paramak.utils import calculate_wedge_cut, patch_workplane

patch_workplane()


class ToroidalFieldCoilRectangleRoundCorners(ExtrudeMixedShape):
Expand Down Expand Up @@ -362,7 +364,7 @@ def create_solid(self):
.consolidateWires()
)

solid = wire.extrude(distance=-self._distance / 2, both=True)
solid = wire.extrude(until=-self._distance / 2, both=True)
solid = self.rotate_solid(solid)

cutting_wedge = calculate_wedge_cut(self)
Expand All @@ -375,7 +377,7 @@ def create_solid(self):
inner_leg_solid = (
inner_leg_solid.polyline(self._inner_leg_connection_points)
.close()
.extrude(distance=-self._distance / 2, both=True)
.extrude(until=-self._distance / 2, both=True)
)

inner_leg_solid = self.rotate_solid(inner_leg_solid)
Expand Down
6 changes: 4 additions & 2 deletions paramak/parametric_shapes/extruded_circle_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from cadquery import Workplane

from paramak import Shape
from paramak.utils import calculate_wedge_cut
from paramak.utils import calculate_wedge_cut, patch_workplane

patch_workplane()


class ExtrudeCircleShape(Shape):
Expand Down Expand Up @@ -102,7 +104,7 @@ def create_solid(self):

self.wire = wire

solid = wire.extrude(distance=extrusion_distance, both=self.extrude_both)
solid = wire.extrude(until=extrusion_distance, both=self.extrude_both)

solid = self.rotate_solid(solid)
cutting_wedge = calculate_wedge_cut(self)
Expand Down
6 changes: 4 additions & 2 deletions paramak/parametric_shapes/extruded_mixed_shape.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional, Tuple

from paramak import Shape
from paramak.utils import calculate_wedge_cut
from paramak.utils import calculate_wedge_cut, patch_workplane

patch_workplane()


class ExtrudeMixedShape(Shape):
Expand Down Expand Up @@ -83,7 +85,7 @@ def create_solid(self):

self.wire = wire

solid = wire.extrude(distance=extrusion_distance, both=self.extrude_both)
solid = wire.extrude(until=extrusion_distance, both=self.extrude_both)

# filleting rectangular port cutter edges
# must be done before azimuthal placement
Expand Down
17 changes: 17 additions & 0 deletions paramak/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,20 @@ def filter(self, object_list):
new_obj_list.append(obj)
print("length(new_obj_list)", len(new_obj_list))
return new_obj_list


def patch_workplane():
"""Going from CadQuery 2.1 to 2.2, the 'distance' arg to extrude was renamed 'until'.
This patch ensures that either version works fine using 'until'.
"""
from cadquery import Workplane

if "distance" in Workplane.extrude.__code__.co_varnames:
extrude_func = Workplane.extrude

def extrude(*args, **kwargs):
if "until" in kwargs.keys():
kwargs["distance"] = kwargs.pop("until")
return extrude_func(*args, **kwargs)

Workplane.extrude = extrude

0 comments on commit f992bf2

Please sign in to comment.