Skip to content

Commit

Permalink
Merge pull request #214 from fusion-energy/adding_translate_to_extrud…
Browse files Browse the repository at this point in the history
…e_shapes

added option to translate shapes
  • Loading branch information
shimwell authored Mar 18, 2022
2 parents cf30eb9 + 953f249 commit d3312da
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 8 deletions.
17 changes: 15 additions & 2 deletions paramak/parametric_shapes/extruded_circle_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ class ExtrudeCircleShape(Shape):
"""Extrudes a circular 3d CadQuery solid from a central point and a radius
Args:
distance: the extrusion distance to use (cm units if used for
neutronics)
distance: the extrusion distance to use
radius: radius of the shape.
extrusion_start_offset:
rotation_angle: rotation_angle of solid created. a cut is performed
from rotation_angle to 360 degrees. Defaults to 360.
extrude_both: if set to True, the extrusion will occur in both
directions. Defaults to True.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand All @@ -34,6 +41,7 @@ def __init__(
0.6,
),
name: str = "extrudecircleshape",
translate: Optional[Tuple[float, float, float]] = None,
**kwargs
):

Expand All @@ -46,6 +54,7 @@ def __init__(
self.extrude_both = extrude_both
self.color = color
self.name = name
self.translate = translate

@property
def radius(self):
Expand Down Expand Up @@ -109,6 +118,10 @@ def create_solid(self):
solid = self.rotate_solid(solid)
cutting_wedge = calculate_wedge_cut(self)
solid = self.perform_boolean_operations(solid, wedge_cut=cutting_wedge)

if self.translate:
solid = solid.translate(self.translate)

self.solid = solid

return solid
17 changes: 15 additions & 2 deletions paramak/parametric_shapes/extruded_mixed_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ class ExtrudeMixedShape(Shape):
straight and spline connections.
Args:
distance: the extrusion distance to use (cm units if used for
neutronics)
distance: the extrusion distance to use
extrude_both: If set to True, the extrusion will occur in both
directions. Defaults to True.
rotation_angle: rotation angle of solid created. A cut is performed
from rotation_angle to 360 degrees. Defaults to 360.0.
extrusion_start_offset:
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand All @@ -31,6 +38,7 @@ def __init__(
0.172,
),
name: str = "extrudemixedshape",
translate: Optional[Tuple[float, float, float]] = None,
**kwargs
):

Expand All @@ -41,6 +49,7 @@ def __init__(
self.extrusion_start_offset = extrusion_start_offset
self.color = color
self.name = name
self.translate = translate

@property
def distance(self):
Expand Down Expand Up @@ -95,6 +104,10 @@ def create_solid(self):
solid = self.rotate_solid(solid)
cutting_wedge = calculate_wedge_cut(self)
solid = self.perform_boolean_operations(solid, wedge_cut=cutting_wedge)

if self.translate:
solid = solid.translate(self.translate)

self.solid = solid

return solid
10 changes: 8 additions & 2 deletions paramak/parametric_shapes/extruded_spline_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ class ExtrudeSplineShape(ExtrudeMixedShape):
connections.
Args:
distance: the extrusion distance to use (cm units if used for
neutronics).
distance: the extrusion distance to use
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand Down
10 changes: 8 additions & 2 deletions paramak/parametric_shapes/extruded_straight_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ class ExtrudeStraightShape(ExtrudeMixedShape):
"""Extrudes a 3d CadQuery solid from points connected with straight lines.
Args:
distance: the extrusion distance to use (cm units if used for
neutronics)
distance: the extrusion distance to use
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand Down
13 changes: 13 additions & 0 deletions paramak/parametric_shapes/rotate_circle_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class RotateCircleShape(Shape):
radius: radius of the shape
rotation_angle: The rotation_angle to use when revolving the solid
(degrees). Defaults to 360.0.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand All @@ -20,6 +27,7 @@ def __init__(
rotation_angle: float = 360.0,
color: Tuple[float, float, float, Optional[float]] = (1.0, 1.0, 0.6),
name: str = "rotatecircleshape",
translate: Optional[Tuple[float, float, float]] = None,
**kwargs
):

Expand All @@ -28,6 +36,7 @@ def __init__(
self.rotation_angle = rotation_angle
self.color = color
self.name = name
self.translate = translate

@property
def rotation_angle(self):
Expand Down Expand Up @@ -60,5 +69,9 @@ def create_solid(self):

solid = self.rotate_solid(solid)
solid = self.perform_boolean_operations(solid)

if self.translate:
solid = solid.translate(self.translate)

self.solid = solid
return solid
13 changes: 13 additions & 0 deletions paramak/parametric_shapes/rotate_mixed_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class RotateMixedShape(Shape):
Args:
rotation_angle: The rotation_angle to use when revolving the solid
(degrees). Defaults to 360.0.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand All @@ -21,13 +28,15 @@ def __init__(
0.705,
),
name: str = "rotatemixedshape",
translate: Optional[Tuple[float, float, float]] = None,
**kwargs
):

super().__init__(color=color, name=name, **kwargs)
self.rotation_angle = rotation_angle
self.color = color
self.name = name
self.translate = translate

@property
def rotation_angle(self):
Expand Down Expand Up @@ -55,5 +64,9 @@ def create_solid(self):

solid = self.rotate_solid(solid)
solid = self.perform_boolean_operations(solid)

if self.translate:
solid = solid.translate(self.translate)

self.solid = solid
return solid
7 changes: 7 additions & 0 deletions paramak/parametric_shapes/rotate_spline_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class RotateSplineShape(RotateMixedShape):
Args:
rotation_angle: The rotation_angle to use when revolving the solid.
Defaults to 360.0.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand Down
7 changes: 7 additions & 0 deletions paramak/parametric_shapes/rotate_straight_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class RotateStraightShape(RotateMixedShape):
Args:
rotation_angle: The rotation angle to use when revolving the solid
(degrees).
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand Down
13 changes: 13 additions & 0 deletions paramak/parametric_shapes/sweep_circle_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class SweepCircleShape(Shape):
force_cross_section: If True, cross-section of solid is forced to be
shape defined by points in workplane at each path_point. Defaults
to False.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand All @@ -36,6 +43,7 @@ def __init__(
0.89,
),
name: str = "sweepcircleshape",
translate: Optional[Tuple[float, float, float]] = None,
**kwargs
):

Expand All @@ -48,6 +56,7 @@ def __init__(
self.force_cross_section = force_cross_section
self.color = color
self.name = name
self.translate = translate

@property
def radius(self):
Expand Down Expand Up @@ -133,5 +142,9 @@ def create_solid(self):

solid = self.rotate_solid(solid)
solid = self.perform_boolean_operations(solid)

if self.translate:
solid = solid.translate(self.translate)

self.solid = solid
return solid
13 changes: 13 additions & 0 deletions paramak/parametric_shapes/sweep_mixed_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class SweepMixedShape(Shape):
force_cross_section (bool, optional): If True, cross-section of solid
is forced to be shape defined by points in workplane at each
path_point. Defaults to False.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand All @@ -35,6 +42,7 @@ def __init__(
0.839,
),
name: str = "sweepmixedshape",
translate: Optional[Tuple[float, float, float]] = None,
**kwargs
):

Expand All @@ -46,6 +54,7 @@ def __init__(
self.force_cross_section = force_cross_section
self.color = color
self.name = name
self.translate = translate

@property
def path_points(self):
Expand Down Expand Up @@ -86,5 +95,9 @@ def create_solid(self):

solid = self.rotate_solid(solid)
solid = self.perform_boolean_operations(solid)

if self.translate:
solid = solid.translate(self.translate)

self.solid = solid
return solid
7 changes: 7 additions & 0 deletions paramak/parametric_shapes/sweep_spline_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class SweepSplineShape(SweepMixedShape):
force_cross_section (bool, optional): If True, cross-setion of solid
is forced to be shape defined by points in workplane at each
path_point. Defaults to False.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand Down
7 changes: 7 additions & 0 deletions paramak/parametric_shapes/sweep_straight_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class SweepStraightShape(SweepMixedShape):
force_cross_section: If True, cross-section of solid is forced to be
shape defined by points in workplane at each path_point. Defaults
to False.
color: the color to use when exporting the shape to CAD formats that
support color. A tuple of three floats each ranging between 0
and 1.
name: the name of the shape, used to name files when exporting and
as a legend in plots.
translate: distance to translate / move the shape by. Specified as
a vector of (X,Y,Z) directions.
"""

def __init__(
Expand Down
20 changes: 20 additions & 0 deletions tests/test_parametric_shapes/test_extrude_straight_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ class TestExtrudeStraightShape(unittest.TestCase):
def setUp(self):
self.test_shape = ExtrudeStraightShape(points=[(10, 10), (10, 30), (30, 30), (30, 10)], distance=30)

def test_translate(self):
"""Checks the shape extends to the bounding box and then translates
the shape and checks it is extended to the new bounding box"""

assert self.test_shape.solid.val().BoundingBox().xmax == 30
assert self.test_shape.solid.val().BoundingBox().xmin == 10
assert self.test_shape.solid.val().BoundingBox().ymax == 15
assert self.test_shape.solid.val().BoundingBox().ymin == -15
assert self.test_shape.solid.val().BoundingBox().zmax == 30
assert self.test_shape.solid.val().BoundingBox().zmin == 10

self.test_shape.translate = (1, 2, 3)

assert self.test_shape.solid.val().BoundingBox().xmax == 30 + 1
assert self.test_shape.solid.val().BoundingBox().xmin == 10 + 1
assert self.test_shape.solid.val().BoundingBox().ymax == 15 + 2
assert self.test_shape.solid.val().BoundingBox().ymin == -15 + 2
assert self.test_shape.solid.val().BoundingBox().zmax == 30 + 3
assert self.test_shape.solid.val().BoundingBox().zmin == 10 + 3

def test_workplane_of_type_cadquery_plane(self):
"""Tests that a Cadquery.Plane is accepted as a workplane entry and
makes a shape with the same volume as the default 'XY' workplane"""
Expand Down
Loading

0 comments on commit d3312da

Please sign in to comment.