Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 65 additions & 56 deletions src/ansys/geometry/core/designer/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,42 +585,13 @@ def add_midsurface_offset(self, offset: MidSurfaceOffsetType) -> None:
@protect_grpc
@check_input_types
def imprint_curves(self, faces: List[Face], sketch: Sketch) -> Tuple[List[Edge], List[Face]]:
# Verify that each of the faces provided are part of this body
body_faces = self.faces
for provided_face in faces:
is_found = False
for body_face in body_faces:
if provided_face.id == body_face.id:
is_found = True
break
if not is_found:
raise ValueError(f"Face with id {provided_face.id} is not part of this body.")

self._grpc_client.log.debug(
f"Imprinting curves provided on {self.id} "
+ f"for faces {[face.id for face in faces]}."
)

imprint_response = self._commands_stub.ImprintCurves(
ImprintCurvesRequest(
body=self._id,
curves=sketch_shapes_to_grpc_geometries(sketch._plane, sketch.edges, sketch.faces),
faces=[face._id for face in faces],
)
raise NotImplementedError(
"""
imprint_curves is not implemented at the TemplateBody level.
Instead, call this method on a Body.
"""
)

new_edges = [
Edge(grpc_edge.id, grpc_edge.curve_type, self, self._grpc_client)
for grpc_edge in imprint_response.edges
]

new_faces = [
Face(grpc_face.id, grpc_face.surface_type, self, self._grpc_client)
for grpc_face in imprint_response.faces
]

return (new_edges, new_faces)

@protect_grpc
@check_input_types
def project_curves(
Expand All @@ -630,28 +601,13 @@ def project_curves(
closest_face: bool,
only_one_curve: Optional[bool] = False,
) -> List[Face]:
curves = sketch_shapes_to_grpc_geometries(
sketch._plane, sketch.edges, sketch.faces, only_one_curve=only_one_curve
)

self._grpc_client.log.debug(f"Projecting provided curves on {self.id}.")

project_response = self._commands_stub.ProjectCurves(
ProjectCurvesRequest(
body=self._id,
curves=curves,
direction=unit_vector_to_grpc_direction(direction),
closest_face=closest_face,
)
raise NotImplementedError(
"""
project_curves is not implemented at the TemplateBody level.
Instead, call this method on a Body.
"""
)

projected_faces = [
Face(grpc_face.id, grpc_face.surface_type, self, self._grpc_client)
for grpc_face in project_response.faces
]

return projected_faces

@protect_grpc
@check_input_types
@reset_tessellation_cache
Expand Down Expand Up @@ -902,7 +858,41 @@ def add_midsurface_offset(self, offset: "MidSurfaceOffsetType") -> None:
self._template.add_midsurface_offset(offset)

def imprint_curves(self, faces: List[Face], sketch: Sketch) -> Tuple[List[Edge], List[Face]]:
return self._template.imprint_curves(faces, sketch)
# Verify that each of the faces provided are part of this body
body_faces = self.faces
for provided_face in faces:
is_found = False
for body_face in body_faces:
if provided_face.id == body_face.id:
is_found = True
break
if not is_found:
raise ValueError(f"Face with id {provided_face.id} is not part of this body.")

self._template._grpc_client.log.debug(
f"Imprinting curves provided on {self.id} "
+ f"for faces {[face.id for face in faces]}."
)

imprint_response = self._template._commands_stub.ImprintCurves(
ImprintCurvesRequest(
body=self._id,
curves=sketch_shapes_to_grpc_geometries(sketch._plane, sketch.edges, sketch.faces),
faces=[face._id for face in faces],
)
)

new_edges = [
Edge(grpc_edge.id, grpc_edge.curve_type, self, self._template._grpc_client)
for grpc_edge in imprint_response.edges
]

new_faces = [
Face(grpc_face.id, grpc_face.surface_type, self, self._template._grpc_client)
for grpc_face in imprint_response.faces
]

return (new_edges, new_faces)

def project_curves(
self,
Expand All @@ -911,7 +901,26 @@ def project_curves(
closest_face: bool,
only_one_curve: Optional[bool] = False,
) -> List[Face]:
return self._template.project_curves(direction, sketch, closest_face, only_one_curve)
curves = sketch_shapes_to_grpc_geometries(
sketch._plane, sketch.edges, sketch.faces, only_one_curve=only_one_curve
)
self._template._grpc_client.log.debug(f"Projecting provided curves on {self.id}.")

project_response = self._template._commands_stub.ProjectCurves(
ProjectCurvesRequest(
body=self._id,
curves=curves,
direction=unit_vector_to_grpc_direction(direction),
closest_face=closest_face,
)
)

projected_faces = [
Face(grpc_face.id, grpc_face.surface_type, self, self._template._grpc_client)
for grpc_face in project_response.faces
]

return projected_faces

def translate(self, direction: UnitVector3D, distance: Union[Quantity, Distance, Real]) -> None:
return self._template.translate(direction, distance)
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def test_project_and_imprint_curves(modeler: Modeler, skip_not_on_linux_service)
"""Test the projection of a set of curves on a body."""
# Create your design on the server side
design = modeler.create_design("ExtrudeSlot")
comp = design.add_component("Comp1")

# Create a Sketch object and draw a couple of slots
imprint_sketch = Sketch()
Expand All @@ -845,7 +846,7 @@ def test_project_and_imprint_curves(modeler: Modeler, skip_not_on_linux_service)
# Extrude the sketch
sketch = Sketch()
sketch.box(Point2D([0, 0], UNITS.mm), Quantity(150, UNITS.mm), Quantity(150, UNITS.mm))
body = design.extrude_sketch(name="MyBox", sketch=sketch, distance=Quantity(50, UNITS.mm))
body = comp.extrude_sketch(name="MyBox", sketch=sketch, distance=Quantity(50, UNITS.mm))
body_faces = body.faces

# Project the curves on the box
Expand Down Expand Up @@ -888,6 +889,10 @@ def test_project_and_imprint_curves(modeler: Modeler, skip_not_on_linux_service)
assert len(new_faces) == 2
assert len(body.faces) == 8

# Make sure we have occurrence faces, not master
assert faces[0].id not in [face.id for face in body._template.faces]
assert new_faces[0].id not in [face.id for face in body._template.faces]


def test_copy_body(modeler: Modeler, skip_not_on_linux_service):
"""Test copying a body."""
Expand Down