def circle_primitive(): circle = factory.new('CIRCLE', dxfattribs={'radius': 3}) return disassemble.make_primitive(circle)
def entity(self): # Default layer is '0' with default ACI color 7 # Default entity color is BYLAYER return factory.new("LINE")
def add_line(s: Vector, e: Vector): dxfattribs['start'] = ucs.to_wcs(s) dxfattribs['end'] = ucs.to_wcs(e) entities.append(factory.new('LINE', dxfattribs))
def test_for_existing_text_style(TYPE, auditor, doc): text = factory.new(TYPE, dxfattribs={'style': 'UNDEFINED'}, doc=doc) auditor.check_text_style(text) assert len(auditor.fixes) == 1 assert auditor.fixes[0].code == AuditError.UNDEFINED_TEXT_STYLE assert text.dxf.style == 'Standard'
def virtual_leader_entities(leader: 'Leader') -> Iterable['DXFGraphic']: # Source: https://atlight.github.io/formats/dxf-leader.html # GDAL: DXF LEADER implementation: # https://github.com/OSGeo/gdal/blob/master/gdal/ogr/ogrsf_frmts/dxf/ogrdxf_leader.cpp # LEADER DXF Reference: # http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-396B2369-F89F-47D7-8223-8B7FB794F9F3 from ezdxf.entities import DimStyleOverride assert leader.dxftype() == 'LEADER' vertices = Vector.list(leader.vertices) # WCS if len(vertices) < 2: # This LEADER entities should be removed by the auditor if loaded or # ignored at exporting, if created by an ezdxf-user (log). raise ValueError('More than 1 vertex required.') dxf = leader.dxf doc = leader.doc # Some default values depend on the measurement system # 0/1 = imperial/metric if doc: measurement = doc.header.get('$MEASUREMENT', 0) else: measurement = 0 # Set default styling attributes values: dimtad = 1 dimgap = 0.625 if measurement else 0.0625 dimscale = 1.0 dimclrd = dxf.color dimltype = dxf.linetype dimlwd = dxf.lineweight override = None if doc: # get styling attributes from associated DIMSTYLE and/or XDATA override override = DimStyleOverride(cast('Dimension', leader)) dimtad = override.get('dimtad', dimtad) dimgap = override.get('dimgap', dimgap) dimscale = override.get('dimscale', dimscale) if dimscale == 0.0: # special but unknown meaning dimscale = 1.0 dimclrd = override.get('dimclrd', dimclrd) dimltype = override.get('dimltype', dimltype) dimlwd = override.get('dimlwd', dimlwd) text_width = dxf.text_width hook_line_vector = Vector(dxf.horizontal_direction) has_text_annotation = dxf.annotation_type == 0 if has_text_annotation and dxf.has_hookline: if dxf.hookline_direction == 1: hook_line_vector = -hook_line_vector if dimtad != 0 and text_width > 0: hook_line = hook_line_vector * (dimgap * dimscale + text_width) vertices.append(vertices[-1] + hook_line) dxfattribs = leader.graphic_properties() dxfattribs['color'] = dimclrd dxfattribs['linetype'] = dimltype dxfattribs['lineweight'] = dimlwd if dxfattribs.get('color') == BYBLOCK: dxfattribs['color'] = dxf.block_color if dxf.path_type == 1: # Spline start_tangent = (vertices[1] - vertices[0]) end_tangent = (vertices[-1] - vertices[-2]) bspline = fit_points_to_cad_cv(vertices, degree=3, tangents=[start_tangent, end_tangent]) spline = cast('Spline', factory.new('SPLINE', doc=doc)) spline.apply_construction_tool(bspline) yield spline else: attribs = dict(dxfattribs) prev = vertices[0] for vertex in vertices[1:]: attribs['start'] = prev attribs['end'] = vertex yield factory.new(dxftype='LINE', dxfattribs=attribs, doc=doc) prev = vertex if dxf.has_arrowhead and override: arrow_name = override.get('dimldrblk', '') if arrow_name is None: return size = override.get('dimasz', 2.5 if measurement else 0.1875) * dimscale rotation = (vertices[0] - vertices[1]).angle_deg if doc and arrow_name in doc.blocks: dxfattribs.update({ 'name': arrow_name, 'insert': vertices[0], 'rotation': rotation, 'xscale': size, 'yscale': size, 'zscale': size, }) # create a virtual block reference insert = cast( 'Insert', factory.new('INSERT', dxfattribs=dxfattribs, doc=doc)) yield from insert.virtual_entities() else: # render standard arrows yield from ARROWS.virtual_entities( name=arrow_name, insert=vertices[0], size=size, rotation=rotation, dxfattribs=dxfattribs, )
def add_line(s: Vec3, e: Vec3): dxfattribs["start"] = ucs.to_wcs(s) dxfattribs["end"] = ucs.to_wcs(e) entities.append(cast("DXFGraphic", factory.new("LINE", dxfattribs)))
def test_map_dxf_point(): point = factory.new("POINT", dxfattribs={"location": (0, 0)}) assert geo.mapping(point) == {"type": "Point", "coordinates": (0, 0)}
def test_make_primitive_for_hatch_is_empty(): hatch = factory.new('HATCH') # make_primitive() returns an empty primitive, because a HATCH entity can # not be reduced into a single path or mesh. prim = disassemble.make_primitive(hatch) assert prim.is_empty
def point(vertex: Sequence) -> Point: point = cast(Point, factory.new("POINT", dxfattribs=dxfattribs)) point.dxf.location = vertex return point
def lwpolyline(vertices: Sequence) -> LWPolyline: polyline = cast(LWPolyline, factory.new("LWPOLYLINE", dxfattribs=dxfattribs)) polyline.append_points(vertices, format="xy") return polyline
def test_update_transparency_by_block_from_gfx_attribs(): attribs = GfxAttribs(transparency=gfxattribs.TRANSPARENCY_BYBLOCK, ) line = factory.new("LINE") line.dxf.update(dict(attribs)) assert line.dxf.transparency == ezdxf.colors.TRANSPARENCY_BYBLOCK
def test_map_dxf_line(): point = factory.new('LINE', dxfattribs={'start': (0, 0), 'end': (1, 0)}) assert geo.mapping(point) == { 'type': 'LineString', 'coordinates': [(0, 0), (1, 0)] }
def test_map_dxf_point(): point = factory.new('POINT', dxfattribs={'location': (0, 0)}) assert geo.mapping(point) == {'type': 'Point', 'coordinates': (0, 0)}
def new_entity(self, type_: str, dxfattribs: dict) -> 'DXFGraphic': entity = factory.new(type_, dxfattribs=dxfattribs) self.entity_space.add(entity) return entity
def test_map_dxf_line(): point = factory.new("LINE", dxfattribs={"start": (0, 0), "end": (1, 0)}) assert geo.mapping(point) == { "type": "LineString", "coordinates": [(0, 0), (1, 0)], }
def test_convert_unsupported_entity_to_primitive(): p = disassemble.make_primitive(factory.new('3DSOLID')) assert p.path is None assert p.mesh is None assert p.is_empty is True assert list(p.vertices()) == []
def virtual_entities(point: 'Point', pdsize: float = 1, pdmode: int = 0) -> List['DXFGraphic']: """ Yields point graphic as DXF primitives LINE and CIRCLE entities. The dimensionless point is rendered as zero-length line! Check for this condition:: e.dxftype() == 'LINE' and e.dxf.start.isclose(e.dxf.end) if the rendering engine can't handle zero-length lines. Args: point: DXF POINT entity pdsize: point size in drawing units pdmode: point styling mode, see :class:`~ezdxf.entities.Point` class .. versionadded:: 0.15 """ def add_line_symmetrical(offset: Vector): dxfattribs['start'] = ucs.to_wcs(-offset) dxfattribs['end'] = ucs.to_wcs(offset) entities.append(factory.new('LINE', dxfattribs)) def add_line(s: Vector, e: Vector): dxfattribs['start'] = ucs.to_wcs(s) dxfattribs['end'] = ucs.to_wcs(e) entities.append(factory.new('LINE', dxfattribs)) center = point.dxf.location # This is not a real OCS! Defines just the point orientation, # location is in WCS! ocs = point.ocs() ucs = UCS(origin=center, ux=ocs.ux, uz=ocs.uz) # The point angle is clockwise oriented: ucs = ucs.rotate_local_z(math.radians(-point.dxf.angle)) entities = [] gfx = point.graphic_properties() radius = pdsize * 0.5 has_circle = bool(pdmode & 32) has_square = bool(pdmode & 64) style = pdmode & 7 dxfattribs = dict(gfx) if style == 0: # . dimensionless point as zero-length line add_line_symmetrical(NULLVEC) # style == 1: no point symbol elif style == 2: # + cross add_line_symmetrical(Vector(pdsize, 0)) add_line_symmetrical(Vector(0, pdsize)) elif style == 3: # x cross add_line_symmetrical(Vector(pdsize, pdsize)) add_line_symmetrical(Vector(pdsize, -pdsize)) elif style == 4: # ' tick add_line(NULLVEC, Vector(0, radius)) if has_square: x1 = -radius x2 = radius y1 = -radius y2 = radius add_line(Vector(x1, y1), Vector(x2, y1)) add_line(Vector(x2, y1), Vector(x2, y2)) add_line(Vector(x2, y2), Vector(x1, y2)) add_line(Vector(x1, y2), Vector(x1, y1)) if has_circle: dxfattribs = dict(gfx) if point.dxf.hasattr('extrusion'): dxfattribs['extrusion'] = ocs.uz dxfattribs['center'] = ocs.from_wcs(center) else: dxfattribs['center'] = center dxfattribs['radius'] = radius entities.append(factory.new('CIRCLE', dxfattribs)) # noinspection PyTypeChecker return entities
def test_multiple_unsupported_entities_to_vertices(): w = factory.new('3DSOLID') primitives = list(disassemble.to_primitives([w, w, w])) assert len(primitives) == 3, "3 empty primitives expected" vertices = list(disassemble.to_vertices(primitives)) assert len(vertices) == 0, "no vertices expected"
def add_line_symmetrical(offset: Vector): dxfattribs['start'] = ucs.to_wcs(-offset) dxfattribs['end'] = ucs.to_wcs(offset) entities.append(factory.new('LINE', dxfattribs))
def test_from_spline(): spline = factory.new('SPLINE') spline.fit_points = [(2, 0), (4, 1), (6, -1), (8, 0)] path = make_path(spline) assert path.start == (2, 0) assert path.end == (8, 0)
def add_line_symmetrical(offset: Vec3): dxfattribs["start"] = ucs.to_wcs(-offset) dxfattribs["end"] = ucs.to_wcs(offset) entities.append(cast("DXFGraphic", factory.new("LINE", dxfattribs)))