예제 #1
0
    def audit(self, auditor: Auditor) -> None:
        """Audit and repair BLOCKS section.

        .. important::

            Do not delete entities while auditing process, because this
            would alter the entity database while iterating, instead use::

                auditor.trash(entity)

            to delete invalid entities after auditing automatically.

        """
        assert self.doc is auditor.doc, "Auditor for different DXF document."

        for block_record in self.block_records:
            assert isinstance(block_record, BlockRecord)
            for entity in block_record.entity_space:
                if not is_graphic_entity(entity):
                    auditor.fixed_error(
                        code=AuditError.REMOVED_INVALID_GRAPHIC_ENTITY,
                        message=f"Removed invalid DXF entity {str(entity)} from"
                        f" BLOCK '{block_record.dxf.name}'.",
                    )
                    auditor.trash(entity)
                elif isinstance(entity, Attrib):
                    # ATTRIB can only exist as an attached entity of the INSERT
                    # entity!
                    auditor.fixed_error(
                        code=AuditError.REMOVED_STANDALONE_ATTRIB_ENTITY,
                        message=f"Removed standalone {str(entity)} entity from"
                        f" BLOCK '{block_record.dxf.name}'.",
                    )
                    auditor.trash(entity)
예제 #2
0
파일: base.py 프로젝트: Rahulghuge94/ezdxf
    def add_entity(self, entity: "DXFGraphic") -> None:
        """Add an existing :class:`DXFGraphic` entity to a layout, but be sure
        to unlink (:meth:`~BaseLayout.unlink_entity`) entity from the previous
        owner layout. Adding entities from a different DXF drawing is not
        supported.
        """
        # bind virtual entities to the DXF document:
        doc = self.doc
        if entity.dxf.handle is None and doc:
            factory.bind(entity, doc)
        handle = entity.dxf.handle
        if handle is None or handle not in self.doc.entitydb:
            raise DXFStructureError(
                "Adding entities from a different DXF drawing is not supported."
            )

        if not is_graphic_entity(entity):
            raise DXFTypeError(f"invalid entity {str(entity)}")
        self.block_record.add_entity(entity)
예제 #3
0
def test_is_not_graphic_entity(entity):
    assert is_graphic_entity(entity) is False
def test_dxf_tag_storage_is_a_non_graphical_entity_by_default():
    assert DXFTagStorage().is_graphic_entity is False
    assert is_graphic_entity(DXFTagStorage()) is False
def test_wrapped_mtext_is_a_graphic_entity(entity):
    assert entity.is_graphic_entity is True
    assert is_graphic_entity(entity) is True
예제 #6
0
def test_wrapped_xrecord_is_not_a_graphic_entity(entity):
    assert is_graphic_entity(entity) is False
예제 #7
0
def test_entity_type(entity):
    assert is_graphic_entity(entity) is False
    assert is_dxf_object(entity) is False