Skip to content

Commit 79fc47c

Browse files
jonahrbRobPasMue
andauthored
FIX: imprint project occurrences (#493)
Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com>
1 parent d27b1d9 commit 79fc47c

File tree

2 files changed

+71
-57
lines changed

2 files changed

+71
-57
lines changed

src/ansys/geometry/core/designer/body.py

Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -585,42 +585,13 @@ def add_midsurface_offset(self, offset: MidSurfaceOffsetType) -> None:
585585
@protect_grpc
586586
@check_input_types
587587
def imprint_curves(self, faces: List[Face], sketch: Sketch) -> Tuple[List[Edge], List[Face]]:
588-
# Verify that each of the faces provided are part of this body
589-
body_faces = self.faces
590-
for provided_face in faces:
591-
is_found = False
592-
for body_face in body_faces:
593-
if provided_face.id == body_face.id:
594-
is_found = True
595-
break
596-
if not is_found:
597-
raise ValueError(f"Face with id {provided_face.id} is not part of this body.")
598-
599-
self._grpc_client.log.debug(
600-
f"Imprinting curves provided on {self.id} "
601-
+ f"for faces {[face.id for face in faces]}."
602-
)
603-
604-
imprint_response = self._commands_stub.ImprintCurves(
605-
ImprintCurvesRequest(
606-
body=self._id,
607-
curves=sketch_shapes_to_grpc_geometries(sketch._plane, sketch.edges, sketch.faces),
608-
faces=[face._id for face in faces],
609-
)
588+
raise NotImplementedError(
589+
"""
590+
imprint_curves is not implemented at the TemplateBody level.
591+
Instead, call this method on a Body.
592+
"""
610593
)
611594

612-
new_edges = [
613-
Edge(grpc_edge.id, grpc_edge.curve_type, self, self._grpc_client)
614-
for grpc_edge in imprint_response.edges
615-
]
616-
617-
new_faces = [
618-
Face(grpc_face.id, grpc_face.surface_type, self, self._grpc_client)
619-
for grpc_face in imprint_response.faces
620-
]
621-
622-
return (new_edges, new_faces)
623-
624595
@protect_grpc
625596
@check_input_types
626597
def project_curves(
@@ -630,28 +601,13 @@ def project_curves(
630601
closest_face: bool,
631602
only_one_curve: Optional[bool] = False,
632603
) -> List[Face]:
633-
curves = sketch_shapes_to_grpc_geometries(
634-
sketch._plane, sketch.edges, sketch.faces, only_one_curve=only_one_curve
635-
)
636-
637-
self._grpc_client.log.debug(f"Projecting provided curves on {self.id}.")
638-
639-
project_response = self._commands_stub.ProjectCurves(
640-
ProjectCurvesRequest(
641-
body=self._id,
642-
curves=curves,
643-
direction=unit_vector_to_grpc_direction(direction),
644-
closest_face=closest_face,
645-
)
604+
raise NotImplementedError(
605+
"""
606+
project_curves is not implemented at the TemplateBody level.
607+
Instead, call this method on a Body.
608+
"""
646609
)
647610

648-
projected_faces = [
649-
Face(grpc_face.id, grpc_face.surface_type, self, self._grpc_client)
650-
for grpc_face in project_response.faces
651-
]
652-
653-
return projected_faces
654-
655611
@protect_grpc
656612
@check_input_types
657613
@reset_tessellation_cache
@@ -902,7 +858,41 @@ def add_midsurface_offset(self, offset: "MidSurfaceOffsetType") -> None:
902858
self._template.add_midsurface_offset(offset)
903859

904860
def imprint_curves(self, faces: List[Face], sketch: Sketch) -> Tuple[List[Edge], List[Face]]:
905-
return self._template.imprint_curves(faces, sketch)
861+
# Verify that each of the faces provided are part of this body
862+
body_faces = self.faces
863+
for provided_face in faces:
864+
is_found = False
865+
for body_face in body_faces:
866+
if provided_face.id == body_face.id:
867+
is_found = True
868+
break
869+
if not is_found:
870+
raise ValueError(f"Face with id {provided_face.id} is not part of this body.")
871+
872+
self._template._grpc_client.log.debug(
873+
f"Imprinting curves provided on {self.id} "
874+
+ f"for faces {[face.id for face in faces]}."
875+
)
876+
877+
imprint_response = self._template._commands_stub.ImprintCurves(
878+
ImprintCurvesRequest(
879+
body=self._id,
880+
curves=sketch_shapes_to_grpc_geometries(sketch._plane, sketch.edges, sketch.faces),
881+
faces=[face._id for face in faces],
882+
)
883+
)
884+
885+
new_edges = [
886+
Edge(grpc_edge.id, grpc_edge.curve_type, self, self._template._grpc_client)
887+
for grpc_edge in imprint_response.edges
888+
]
889+
890+
new_faces = [
891+
Face(grpc_face.id, grpc_face.surface_type, self, self._template._grpc_client)
892+
for grpc_face in imprint_response.faces
893+
]
894+
895+
return (new_edges, new_faces)
906896

907897
def project_curves(
908898
self,
@@ -911,7 +901,26 @@ def project_curves(
911901
closest_face: bool,
912902
only_one_curve: Optional[bool] = False,
913903
) -> List[Face]:
914-
return self._template.project_curves(direction, sketch, closest_face, only_one_curve)
904+
curves = sketch_shapes_to_grpc_geometries(
905+
sketch._plane, sketch.edges, sketch.faces, only_one_curve=only_one_curve
906+
)
907+
self._template._grpc_client.log.debug(f"Projecting provided curves on {self.id}.")
908+
909+
project_response = self._template._commands_stub.ProjectCurves(
910+
ProjectCurvesRequest(
911+
body=self._id,
912+
curves=curves,
913+
direction=unit_vector_to_grpc_direction(direction),
914+
closest_face=closest_face,
915+
)
916+
)
917+
918+
projected_faces = [
919+
Face(grpc_face.id, grpc_face.surface_type, self, self._template._grpc_client)
920+
for grpc_face in project_response.faces
921+
]
922+
923+
return projected_faces
915924

916925
def translate(self, direction: UnitVector3D, distance: Union[Quantity, Distance, Real]) -> None:
917926
return self._template.translate(direction, distance)

tests/integration/test_design.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ def test_project_and_imprint_curves(modeler: Modeler, skip_not_on_linux_service)
836836
"""Test the projection of a set of curves on a body."""
837837
# Create your design on the server side
838838
design = modeler.create_design("ExtrudeSlot")
839+
comp = design.add_component("Comp1")
839840

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

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

892+
# Make sure we have occurrence faces, not master
893+
assert faces[0].id not in [face.id for face in body._template.faces]
894+
assert new_faces[0].id not in [face.id for face in body._template.faces]
895+
891896

892897
def test_copy_body(modeler: Modeler, skip_not_on_linux_service):
893898
"""Test copying a body."""

0 commit comments

Comments
 (0)