From fe0be0cdae22123016ff847f984d4155755e3765 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 11 Sep 2024 15:05:18 +0500 Subject: [PATCH] shape_builder.create_axis2_placement_2d --- .../ifcopenshell/util/shape_builder.py | 23 +++++++++++-------- .../test/geom/geometry_tests.py | 8 +++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py index 57868109ba..822f012925 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py @@ -228,10 +228,8 @@ class ShapeBuilder: :return: IfcCircle :rtype: ifcopenshell.entity_instance """ - ifc_center = self.file.createIfcAxis2Placement2D(self.file.createIfcCartesianPoint(center)) + ifc_center = self.create_axis2_placement_2d(center) ifc_curve = self.file.createIfcCircle(ifc_center, radius) - - # self.file_file.createIfcAxis2Placement2D(tool.Ifc.get().createIfcCartesianPoint(center[0:2])) return ifc_curve def plane( @@ -324,9 +322,7 @@ class ShapeBuilder: for further extrusion. """ direction = self.file.createIfcDirection(ref_x_direction) - ifc_position = self.file.createIfcAxis2Placement2D( - self.file.createIfcCartesianPoint(position), RefDirection=direction - ) + ifc_position = self.create_axis2_placement_2d(position, direction) ifc_ellipse = self.file.createIfcEllipse( Position=ifc_position, SemiAxis1=x_axis_radius, SemiAxis2=y_axis_radius ) @@ -373,9 +369,7 @@ class ShapeBuilder: "OuterCurve": outer_curve, } if self.file.schema == "IFC2X3": - kwargs["Position"] = self.file.create_entity( - "IfcAxis2Placement2D", self.file.create_entity("IfcCartesianPoint", [0.0, 0.0]) - ) + kwargs["Position"] = self.create_axis2_placement_2d() if inner_curves: if not isinstance(inner_curves, collections.abc.Iterable): @@ -584,6 +578,17 @@ class ShapeBuilder: position=matrix[:, 3][:3].tolist(), z_axis=matrix[:, 2][:3].tolist(), x_axis=matrix[:, 0][:3].tolist() ) + def create_axis2_placement_2d( + self, position: VectorTuple = (0.0, 0.0), x_direction: Optional[VectorTuple] = None + ) -> ifcopenshell.entity_instance: + """Create IfcAxis2Placement2D.""" + ref_direction = self.file.create_entity("IfcDirection", x_direction) if x_direction else None + return self.file.create_entity( + "IfcAxis2Placement2D", + Location=self.file.create_entity("IfcCartesianPoint", position), + RefDirection=ref_direction, + ) + def mirror( self, curve_or_item: Union[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance]], diff --git a/src/ifcopenshell-python/test/geom/geometry_tests.py b/src/ifcopenshell-python/test/geom/geometry_tests.py index 1ecfa35b4b..92a8f14da6 100644 --- a/src/ifcopenshell-python/test/geom/geometry_tests.py +++ b/src/ifcopenshell-python/test/geom/geometry_tests.py @@ -31,12 +31,10 @@ class TestCreatingShapes(test.bootstrap.IFC4): assert shape.verts def test_create_IfcEllipse(self): - ifc_position = self.file.create_entity( - "IfcAxis2Placement2D", - self.file.create_entity("IfcCartesianPoint", V(0, 0)), - RefDirection=self.file.create_entity("IfcDirection", V(1, 0)), + builder = ShapeBuilder(self.file) + item = self.file.create_entity( + "IfcEllipse", Position=builder.create_axis2_placement_2d(), SemiAxis1=1.0, SemiAxis2=0.5 ) - item = self.file.create_entity("IfcEllipse", Position=ifc_position, SemiAxis1=1.0, SemiAxis2=0.5) settings = ifcopenshell.geom.settings() shape = ifcopenshell.geom.create_shape(settings, item) assert shape.verts