diff --git a/src/ansys/geometry/core/designer/body.py b/src/ansys/geometry/core/designer/body.py index 1afb7cdb4f..2924ab8abe 100644 --- a/src/ansys/geometry/core/designer/body.py +++ b/src/ansys/geometry/core/designer/body.py @@ -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( @@ -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 @@ -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, @@ -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) diff --git a/tests/integration/test_design.py b/tests/integration/test_design.py index 47b77b084e..6e103de498 100644 --- a/tests/integration/test_design.py +++ b/tests/integration/test_design.py @@ -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() @@ -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 @@ -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."""