def test_multi_leader_entities(self): # ATTRIBUTE_TRUE_COLOR; size: 12 # UNKNOWN_TYPE_51; size: 12 # ATTRIBUTE_MARKER; size: 12 # UNICODE_TEXT2; size: 200 # UNKNOWN_TYPE_51; size: 12 # ATTRIBUTE_LAYER; size: 12 # ATTRIBUTE_TRUE_COLOR; size: 12 # ATTRIBUTE_LINETYPE; size: 12 # ATTRIBUTE_MARKER; size: 12 # ATTRIBUTE_FILL; size: 12 # POLYGON; size: 84 # ATTRIBUTE_MARKER; size: 12 # POLYLINE; size: 60 # ATTRIBUTE_MARKER; size: 12 # POLYLINE; size: 60 # ATTRIBUTE_TRUE_COLOR; size: 12 # ATTRIBUTE_LINETYPE; size: 12 # ATTRIBUTE_LINEWEIGHT; size: 12 # ATTRIBUTE_MARKER; size: 12 # ATTRIBUTE_TRUE_COLOR; size: 12 # ATTRIBUTE_LINETYPE; size: 12 # ATTRIBUTE_LINEWEIGHT; size: 12 # UNKNOWN_TYPE_51; size: 12 parser = ProxyGraphic(load_proxy_graphic(Tags.from_text(MULITILEADER))) indices = list(parser.info()) assert len(indices) == 23 entities = list(parser.virtual_entities()) assert len(entities) == 4 text = entities[0] assert text.dxftype() == 'TEXT' assert text.dxf.text == 'W410' assert text.dxf.layer == '0' # no DXF document available assert text.dxf.color == 256 # by layer assert text.dxf.linetype == 'BYLAYER' # no DXF document available assert text.rgb == (0, 0, 192) # ??? polyline = entities[1] # POLYGON assert polyline.dxftype() == 'POLYLINE' assert len(polyline.vertices) == 3 assert text.dxf.layer == '0' # no DXF document available assert text.dxf.color == 256 # by layer assert text.dxf.linetype == 'BYLAYER' # no DXF document available assert polyline.is_closed is True polyline = entities[2] assert polyline.is_closed is False assert polyline.dxftype() == 'POLYLINE' assert len(polyline.vertices) == 2 assert text.dxf.layer == '0' # no DXF document available assert text.dxf.color == 256 # by layer assert text.dxf.linetype == 'BYLAYER' # no DXF document available polyline = entities[3] assert polyline.is_closed is False assert polyline.dxftype() == 'POLYLINE' assert len(polyline.vertices) == 2 assert text.dxf.layer == '0' # no DXF document available assert text.dxf.color == 256 # by layer assert text.dxf.linetype == 'BYLAYER' # no DXF document available
def test_lwpolyline_still_raises_consolidated_exception(self): parser = ProxyGraphic( load_proxy_graphic(Tags.from_text(LWPOLYLINE_DATA))) with pytest.raises(ProxyGraphicError): list(parser.virtual_entities()) with pytest.raises(ProxyGraphicError): list(parser.__virtual_entities__())
def test_multi_leader_entities(self): # ATTRIBUTE_TRUE_COLOR; size: 12 # UNKNOWN_TYPE_51; size: 12 # ATTRIBUTE_MARKER; size: 12 # UNICODE_TEXT2; size: 200 # UNKNOWN_TYPE_51; size: 12 # ATTRIBUTE_LAYER; size: 12 # ATTRIBUTE_TRUE_COLOR; size: 12 # ATTRIBUTE_LINETYPE; size: 12 # ATTRIBUTE_MARKER; size: 12 # ATTRIBUTE_FILL; size: 12 # POLYGON; size: 84 # ATTRIBUTE_MARKER; size: 12 # POLYLINE; size: 60 # ATTRIBUTE_MARKER; size: 12 # POLYLINE; size: 60 # ATTRIBUTE_TRUE_COLOR; size: 12 # ATTRIBUTE_LINETYPE; size: 12 # ATTRIBUTE_LINEWEIGHT; size: 12 # ATTRIBUTE_MARKER; size: 12 # ATTRIBUTE_TRUE_COLOR; size: 12 # ATTRIBUTE_LINETYPE; size: 12 # ATTRIBUTE_LINEWEIGHT; size: 12 # UNKNOWN_TYPE_51; size: 12 parser = ProxyGraphic(load_proxy_graphic(Tags.from_text(MULITILEADER))) indices = list(parser.info()) assert len(indices) == 23 entities = list(parser.virtual_entities()) assert len(entities) == 4 text = entities[0] assert text.dxftype() == "TEXT" assert text.dxf.text == "W410" assert text.dxf.layer == "0" # no DXF document available assert text.dxf.color == 256 # by layer assert text.dxf.linetype == "BYLAYER" # no DXF document available assert text.dxf.true_color is None hatch = entities[1] # POLYGON assert hatch.dxftype() == "HATCH" assert len(hatch.paths[0].vertices) == 3 assert hatch.dxf.layer == "0" # no DXF document available assert hatch.dxf.color == 256 # by layer assert hatch.dxf.linetype == "BYLAYER" # no DXF document available polyline = entities[2] assert polyline.is_closed is False assert polyline.dxftype() == "POLYLINE" assert len(polyline.vertices) == 2 assert polyline.dxf.layer == "0" # no DXF document available assert polyline.dxf.color == 256 # by layer assert polyline.dxf.linetype == "BYLAYER" # no DXF document available polyline = entities[3] assert polyline.is_closed is False assert polyline.dxftype() == "POLYLINE" assert len(polyline.vertices) == 2 assert polyline.dxf.layer == "0" # no DXF document available assert polyline.dxf.color == 256 # by layer assert polyline.dxf.linetype == "BYLAYER" # no DXF document available
def draw_proxy_graphic(self, data: bytes, doc) -> None: if data: try: self.draw_entities(virtual_entities(ProxyGraphic(data, doc))) except ProxyGraphicError as e: print(str(e)) print(POST_ISSUE_MSG)
def __virtual_entities__(self) -> Iterable[DXFGraphic]: """Implements the SupportsVirtualEntities protocol. """ from ezdxf.proxygraphic import ProxyGraphic if self.proxy_graphic: for e in ProxyGraphic(self.proxy_graphic, self.doc).virtual_entities(): e.set_source_of_copy(self) yield e return []
def test_circular_arc_entities(self): # example "aec_doors_walls.dxf" of issue #497; ACAD_PROXY_ENTITY <59D> parser = ProxyGraphic(load_proxy_graphic(Tags.from_text(ARC_AEC_DOOR))) indices = list(parser.info()) # [ # ... # (96, 108, 'POLYGON'), # (204, 108, 'POLYGON'), # (312, 100, 'CIRCULAR_ARC'), # (412, 100, 'CIRCULAR_ARC'), # (512, 108, 'POLYGON'), # (620, 108, 'POLYGON') # ] assert len(indices) == 13 entities = list(parser.virtual_entities()) assert len(entities) == 6 # 1. ARC - clockwise oriented arc1 = entities[2] assert arc1.dxf.extrusion.isclose( (0, 0, -1)), "expected inverted extrusion vector" assert arc1.dxf.center.isclose( (-9333.398890018769, 10110.240054080468, 0.0) # OCS! ) assert arc1.dxf.start_angle == pytest.approx(90.0003859699524) assert arc1.dxf.end_angle == pytest.approx(-179.9996140300476) assert arc1.dxf.radius == pytest.approx(850) # 2. ARC - regular counter clockwise oriented arc arc2 = entities[3] assert arc2.dxf.extrusion.isclose( (0, 0, 1)), "expected WCS aligned extrusion vector" assert arc2.dxf.center.isclose( (9333.41034197779, 11810.240054041897, 0.0) # OCS == WCS ) assert arc2.dxf.start_angle == pytest.approx(-90.0003859699524) assert arc2.dxf.end_angle == pytest.approx(-0.0003859699524042526) assert arc2.dxf.radius == pytest.approx(850)
def test_image_entities(self): # UNICODE_TEXT2; size: 204 # POLYLINE; size: 132 parser = ProxyGraphic(load_proxy_graphic(Tags.from_text(IMAGE))) indices = list(parser.info()) assert len(indices) == 2 entities = list(parser.virtual_entities()) assert len(indices) == 2 text = entities[0] assert text.dxftype() == "TEXT" assert text.dxf.text == "AcDbRasterImage" assert text.dxf.layer == "0" # no DXF document available assert text.dxf.color == 256 # by layer assert text.dxf.linetype == "BYLAYER" # no DXF document available polyline = entities[1] assert polyline.is_closed is False assert polyline.dxftype() == "POLYLINE" assert len(polyline.vertices) == 5 assert text.dxf.layer == "0" # no DXF document available assert text.dxf.color == 256 # by layer assert text.dxf.linetype == "BYLAYER" # no DXF document available
def recursive_decompose(entities: Iterable[DXFEntity]) -> Iterable[DXFEntity]: """ Recursive decomposition of the given DXF entity collection into a flat DXF entity stream. All block references (INSERT) and entities which provide a :meth:`virtual_entities` method will be disassembled into simple DXF sub-entities, therefore the returned entity stream does not contain any INSERT entity. Point entities will **not** be disassembled into DXF sub-entities, as defined by the current point style $PDMODE. These entity types include sub-entities and will be decomposed into simple DXF entities: - INSERT - DIMENSION - LEADER - MLEADER - MLINE Decomposition of XREF, UNDERLAY and ACAD_TABLE entities is not supported. """ def insert(i: 'Insert') -> Iterable[DXFEntity]: yield from i.attribs yield from i.virtual_entities() for entity in entities: dxftype = entity.dxftype() # ignore this virtual_entities() methods: if dxftype in ('POINT', 'LWPOLYLINE', 'POLYLINE'): yield entity elif dxftype == 'INSERT': entity = cast('Insert', entity) if entity.mcount > 1: for virtual_insert in entity.multi_insert(): yield from insert(virtual_insert) else: yield from insert(entity) elif hasattr(entity, 'virtual_entities'): # could contain block references: yield from recursive_decompose(entity.virtual_entities()) # As long as MLeader.virtual_entities() is not implemented, # use existing proxy graphic: elif dxftype in ('MLEADER', 'MULTILEADER') and entity.proxy_graphic: yield from ProxyGraphic(entity.proxy_graphic, entity.doc).virtual_entities() else: yield entity
def draw_proxy_graphic(self, entity: DXFGraphic) -> None: if entity.proxy_graphic: gfx = ProxyGraphic(entity.proxy_graphic, entity.doc) self.draw_entities(gfx.virtual_entities())
def test_info(self, parser: ProxyGraphic): indices = list(parser.info()) assert len(indices) == 13 index, size, type_ = indices[0] assert (index, size, type_) == (8, 84, "POLYLINE_WITH_NORMALS")
def parser(self, data: bytes) -> ProxyGraphic: return ProxyGraphic(data)
def test_raw_exception_in_lwpolyline_parser(self): # TODO: fix error in LWPOLYLINE proxy graphic entity parser = ProxyGraphic( load_proxy_graphic(Tags.from_text(LWPOLYLINE_DATA))) with pytest.raises(IndexError): list(parser.unsafe_virtual_entities())
00C0DC003571AE5F40043422DDA4515D40000000000000000000000000000000000000000000000000000000000000F03F64000000040000001EA72DF9806A69402CE3B4E7B59D34400000000000000000770FBC9D50855E4000000000000000000000000000000000000000000000F03FB634003D352CE93FB1DDE561C5C1 310 E33F00000000000000000418DC3967E1F83F000000000C0000001200000000000000D0000000260000001F8BC5F8B8B46A40197732241FF06140000000000000000000000000000000000000000000000000000000000000F03F0943D77B25BDEF3F417457E0C451C0BF00000000000000003100370032002C003400320000 310 00000006000000010000000000000000000440000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000000000000000000000000000000041007200690061006C00000061007200690061006C002E007400740066000000000000000C00000012000000FF7F0000 310 6400000004000000813C33FBB3606A400278BF21B8F4614000000000000000009AEFA7C64B37034000000000000000000000000000000000000000000000F03F0943D77B25BDEF3F437457E0C451C0BF0000000000000000182D4454FB210940000000000C00000010000000010000000C0000001700000000000000540000 310 0020000000020000001EA72DF9806A69402CE3B4E7B59D344000000000000000001EA72DF9806A69402CE3B4E7B59D3440000000000000000000000000000000000000000000000000000000000000F03F540000002000000002000000B296839B8D1A724001000000F06355400000000000000000B296839B8D1A72400100 310 0000F0635540000000000000000000000000000000000000000000000000000000000000F03F540000002000000002000000632D073753076140FFFFFFFF2F525A400000000000000000632D073753076140FFFFFFFF2F525A40000000000000000000000000000000000000000000000000000000000000F03F5400000020 310 000000020000000960E446A3456F405AF2DBF448AB604000000000000000000960E446A3456F405AF2DBF448AB6040000000000000000000000000000000000000000000000000000000000000F03F """ doc = ezdxf.new() msp = doc.modelspace() data = load_proxy_graphic(Tags.from_text(DATA)) proxy = ProxyGraphic(data, doc) for index, size, name in proxy.info(): print(f'Index: {index}, Size: {size}, Type: {name}') for entity in proxy.virtual_entities(): print(str(entity)) doc.entitydb.add(entity) msp.add_entity(entity) doc.saveas(DIR / 'proxy.dxf')