def test_to_poly_path_hatches_with_ocs(self, path1): m = Matrix44.x_rotate(math.pi / 4) path = path1.transform(m) extrusion = m.transform((0, 0, 1)) hatches = list(to_hatches(path, edge_path=False, extrusion=extrusion)) h0 = hatches[0] assert h0.dxf.elevation == (0, 0, 1) assert h0.dxf.extrusion.isclose(extrusion) polypath0 = h0.paths[0] assert polypath0.vertices[0] == (0, 0, 0) # x, y, bulge assert polypath0.vertices[-1] == (0, 0, 0), "should be closed automatically"
def test_to_edge_path_hatches(self, path): hatches = list(to_hatches(path, edge_path=True)) assert len(hatches) == 1 h0 = hatches[0] assert h0.dxftype() == "HATCH" assert len(h0.paths) == 1 edge_path = h0.paths[0] assert edge_path.type == BoundaryPathType.EDGE line, spline = edge_path.edges assert line.type == EdgeType.LINE assert line.start == (0, 0) assert line.end == (4, 0) assert spline.type == EdgeType.SPLINE assert close_vectors( Vec3.generate(spline.control_points), [(4, 0), (3, 1), (1, 1), (0, 0)], )
def test_to_edge_path_hatches(self, path): hatches = list(to_hatches(path, edge_path=True)) assert len(hatches) == 1 h0 = hatches[0] assert h0.dxftype() == 'HATCH' assert len(h0.paths) == 1 edge_path = h0.paths[0] assert edge_path.PATH_TYPE == 'EdgePath' line, spline = edge_path.edges assert line.EDGE_TYPE == 'LineEdge' assert line.start == (0, 0) assert line.end == (4, 0) assert spline.EDGE_TYPE == 'SplineEdge' assert spline.control_points[0] == (4, 0) assert spline.control_points[1] == (3, 1) # 2D OCS entity assert spline.control_points[2] == (1, 1) # 2D OCS entity assert spline.control_points[3] == (0, 0)
def test_to_edge_path_hatches(self, path): hatches = list(to_hatches(path, edge_path=True)) assert len(hatches) == 1 h0 = hatches[0] assert h0.dxftype() == 'HATCH' assert len(h0.paths) == 1 edge_path = h0.paths[0] assert edge_path.PATH_TYPE == 'EdgePath' line, spline = edge_path.edges assert line.EDGE_TYPE == 'LineEdge' assert line.start == (0, 0) assert line.end == (4, 0) assert spline.EDGE_TYPE == 'SplineEdge' assert close_vectors(Vec3.generate(spline.control_points), [(4, 0), (3, 1), (1, 1), (0, 0)])
def make_hatches_from_str( s: str, font: fonts.FontFace, size: float = 1.0, align=TextEntityAlignment.LEFT, length: float = 0, dxfattribs=None, m: Matrix44 = None, ) -> List[Hatch]: """Convert a single line string `s` into a list of virtual :class:`~ezdxf.entities.Hatch` entities. The text `size` is the height of the uppercase letter "X" (cap height). The paths are aligned about the insertion point at (0, 0). The HATCH entities are aligned to this insertion point. BASELINE means the bottom of the letter "X". Args: s: text to convert font: font face definition as :class:`~ezdxf.tools.fonts.FontFace` object size: text size (cap height) in drawing units align: alignment as :class:`ezdxf.enums.TextEntityAlignment`, default is :attr:`LEFT` length: target length for the :attr:`ALIGNED` and :attr:`FIT` alignments dxfattribs: additional DXF attributes m: transformation :class:`~ezdxf.math.Matrix44` .. version changed: 0.17.2 Enum :class:`ezdxf.enums.TextEntityAlignment` replaces string values. """ # HATCH is an OCS entity, transforming just the polyline paths # is not correct! The Hatch has to be created in the xy-plane! paths = make_paths_from_str(s, font, size, align, length) dxfattribs = dict(dxfattribs or {}) dxfattribs.setdefault("solid_fill", 1) dxfattribs.setdefault("pattern_name", "SOLID") dxfattribs.setdefault("color", const.BYLAYER) hatches = path.to_hatches(paths, edge_path=True, dxfattribs=dxfattribs) if m is not None: # Transform HATCH entities as a unit: return [hatch.transform(m) for hatch in hatches] # type: ignore else: return list(hatches)
def make_hatches_from_entity(entity: AnyText) -> List[Hatch]: """Convert text content from DXF entities TEXT and ATTRIB into a list of virtual :class:`~ezdxf.entities.Hatch` entities. The hatches are placed at the same location as the source entity and have the same DXF attributes as the source entity. """ check_entity_type(entity) extrusion = entity.dxf.extrusion attribs = entity.graphic_properties() paths = make_paths_from_entity(entity) return list( path.to_hatches( paths, edge_path=True, extrusion=extrusion, dxfattribs=attribs, ))
def make_hatches_from_str(s: str, font: fonts.FontFace, size: float = 1.0, align: str = 'LEFT', length: float = 0, dxfattribs: Dict = None, m: Matrix44 = None) -> List[Hatch]: """ Convert a single line string `s` into a list of virtual :class:`~ezdxf.entities.Hatch` entities. The text `size` is the height of the uppercase letter "X" (cap height). The paths are aligned about the insertion point at (0, 0). The HATCH entities are aligned to this insertion point. BASELINE means the bottom of the letter "X". Args: s: text to convert font: font face definition size: text size (cap height) in drawing units align: alignment as string, default is "LEFT" length: target length for the "ALIGNED" and "FIT" alignments dxfattribs: additional DXF attributes m: transformation :class:`~ezdxf.math.Matrix44` """ # HATCH is an OCS entity, transforming just the polyline paths # is not correct! The Hatch has to be created in the xy-plane! paths = make_paths_from_str(s, font, size, align, length) dxfattribs = dxfattribs or dict() dxfattribs.setdefault('solid_fill', 1) dxfattribs.setdefault('pattern_name', 'SOLID') dxfattribs.setdefault('color', const.BYLAYER) hatches = path.to_hatches( paths, edge_path=True, dxfattribs=dxfattribs) if m is not None: # Transform HATCH entities as a unit: return [hatch.transform(m) for hatch in hatches] else: return list(hatches)
def test_to_poly_path_hatches_with_wcs_elevation(self, path1): hatches = list(to_hatches(path1, edge_path=False)) ho = hatches[0] assert ho.dxf.elevation.isclose((0, 0, 1))
def test_to_poly_path_hatches(self, path): hatches = list(to_hatches(path, edge_path=False)) assert len(hatches) == 1 h0 = hatches[0] assert h0.dxftype() == "HATCH" assert len(h0.paths) == 1
def test_empty_to_hatches(self): assert list(to_hatches([])) == []