def mapping(entity: DXFGraphic, distance: float = MAX_FLATTENING_DISTANCE, force_line_string: bool = False) -> Dict: """ Create the compiled ``__geo_interface__`` mapping as :class:`dict` for the given DXF `entity`, all coordinates are :class:`Vec3` objects and represents "Polygon" always as tuple (exterior, holes) even without holes. Internal API - result is **not** a valid ``_geo_interface__`` mapping! Args: entity: DXF entity distance: maximum flattening distance for curve approximations force_line_string: by default this function returns Polygon objects for closed geometries like CIRCLE, SOLID, closed POLYLINE and so on, by setting argument `force_line_string` to ``True``, this entities will be returned as LineString objects. """ dxftype = entity.dxftype() if dxftype == 'POINT': return {TYPE: POINT, COORDINATES: entity.dxf.location} elif dxftype == 'LINE': return line_string_mapping([entity.dxf.start, entity.dxf.end]) elif dxftype == 'POLYLINE': entity = cast('Polyline', entity) if entity.is_3d_polyline or entity.is_2d_polyline: # May contain arcs as bulge values: path = make_path(entity) points = list(path.flattening(distance)) return _line_string_or_polygon_mapping(points, force_line_string) else: raise TypeError('Polymesh and Polyface not supported.') elif dxftype == 'LWPOLYLINE': # May contain arcs as bulge values: path = make_path(entity) points = list(path.flattening(distance)) return _line_string_or_polygon_mapping(points, force_line_string) elif dxftype in {'CIRCLE', 'ARC', 'ELLIPSE', 'SPLINE'}: return _line_string_or_polygon_mapping( list(entity.flattening(distance)), force_line_string) elif dxftype in {'SOLID', 'TRACE', '3DFACE'}: return _line_string_or_polygon_mapping(entity.wcs_vertices(close=True), force_line_string) elif dxftype == 'HATCH': return _hatch_as_polygon(entity, distance, force_line_string) else: raise TypeError(dxftype)
def _convert_entity(self): e: 'Polyline' = cast('Polyline', self.entity) if e.is_2d_polyline or e.is_3d_polyline: self._path = make_path(e) else: m = MeshVertexMerger.from_polyface(e) self._mesh = MeshBuilder.from_builder(m)
def draw_curve_entity(self, entity: DXFGraphic, properties: Properties) -> None: try: path = make_path(entity) except AttributeError: # API usage error raise TypeError(f"Unsupported DXF type {entity.dxftype()}") self.out.draw_path(path, properties)
def test_issue_224_end_points(ellipse): p = make_path(ellipse) assert ellipse.start_point.isclose(p.start) assert ellipse.end_point.isclose(p.end) # end point locations measured in BricsCAD: assert ellipse.start_point.isclose((2191.3054, -1300.8375), abs_tol=1e-4) assert ellipse.end_point.isclose((2609.7870, -1520.6677), abs_tol=1e-4)
def _convert_entity(self): e: 'LWPolyline' = cast('LWPolyline', self.entity) if e.has_width: # use a mesh representation: tb = TraceBuilder.from_polyline(e) mb = MeshVertexMerger() # merges coincident vertices for face in tb.faces(): mb.add_face(Vec3.generate(face)) self._mesh = MeshBuilder.from_builder(mb) else: # use a path representation to support bulges! self._path = make_path(e)
def draw_polyline_entity(self, entity: DXFGraphic, properties: Properties) -> None: dxftype = entity.dxftype() if dxftype == 'POLYLINE': e = cast(Polyface, entity) if e.is_polygon_mesh or e.is_poly_face_mesh: # draw 3D mesh or poly-face entity self.draw_mesh_builder_entity( MeshBuilder.from_polyface(e), properties, ) return entity = cast(Union[LWPolyline, Polyline], entity) is_lwpolyline = dxftype == 'LWPOLYLINE' if entity.has_width: # draw banded 2D polyline elevation = 0.0 ocs = entity.ocs() transform = ocs.transform if transform: if is_lwpolyline: # stored as float elevation = entity.dxf.elevation else: # stored as vector (0, 0, elevation) elevation = Vec3(entity.dxf.elevation).z trace = TraceBuilder.from_polyline( entity, segments=self.circle_approximation_count // 2) for polygon in trace.polygons(): # polygon is a sequence of Vec2() if transform: points = ocs.points_to_wcs( Vec3(v.x, v.y, elevation) for v in polygon) else: points = Vec3.generate(polygon) # Set default SOLID filling for LWPOLYLINE properties.filling = Filling() self.out.draw_filled_polygon(points, properties) return path = make_path(entity) self.out.draw_path(path, properties)
def _convert_entity(self): vp = self.entity if vp.dxf.status == 0: # Viewport is off return # empty primitive self._path = make_path(vp)
def _convert_entity(self): self._path = make_path(self.entity)
def path(self) -> Optional[Path]: """ Create path representation on demand. """ if self._path is None: self._path = make_path(self.entity) return self._path
# Copyright (c) 2020, Manfred Moitzi # License: MIT License import ezdxf from ezdxf.render import make_path doc = ezdxf.new() msp = doc.modelspace() ellipse = msp.add_ellipse( center=(1999.488177113287, -1598.02265357955, 0.0), major_axis=(629.968069297, 0.0, 0.0), ratio=0.495263197, start_param=-1.261396328799999, end_param=-0.2505454928, dxfattribs={ 'layer': "0", 'linetype': "Continuous", 'color': 3, 'extrusion': (0.0, 0.0, -1.0), }, ) p = make_path(ellipse) msp.add_lwpolyline(p.approximate(), dxfattribs={ 'layer': 'PathRendering', 'color': 1, }) doc.set_modelspace_vport(500, (2400, -1400)) doc.saveas('path_rendering.dxf')
def test_lwpolyline_to_path(i329): p = make_path(i329) assert len(p) == 18 vertices = list(p.flattening(0.01)) assert len(vertices) == 141