Exemple #1
0
 def trash(self, entity: DXFEntity) -> None:
     if entity is None or not entity.is_alive:
         return
     if self.has_trashcan and entity.dxf.handle is not None:
         self._trashcan.add(entity.dxf.handle)
     else:
         entity.destroy()
Exemple #2
0
def entities():
    return [
        DXFEntity.new(handle='A'),
        DXFEntity.new(handle='D'),
        DXFEntity.new(handle='B'),
        DXFEntity.new(handle='C'),
    ]
Exemple #3
0
def test_do_not_copy_source_block_reference():
    e = DXFEntity()
    insert = Insert()
    e.set_source_block_reference(insert)
    copy = e.copy()
    assert copy.has_source_block_reference is False
    assert copy.source_block_reference is None
Exemple #4
0
def test_default_constructor():
    entity = DXFEntity()
    assert entity.dxftype() == "DXFENTITY"
    assert entity.dxf.handle is None
    assert entity.dxf.owner is None
    assert entity == entity
    assert entity != DXFEntity()
Exemple #5
0
 def check_owner_exist(self, entity: DXFEntity) -> None:
     assert self.doc is entity.doc, "Entity from different DXF document."
     if not entity.dxf.hasattr("owner"):  # important for recover mode
         return
     doc = self.doc
     owner_handle = entity.dxf.owner
     handle = entity.dxf.get("handle", "0")
     if owner_handle == "0":
         # Root-Dictionary or Table-Head:
         if handle == self._rootdict_handle or entity.dxftype() == "TABLE":
             return  # '0' handle as owner is valid
     if owner_handle not in doc.entitydb:
         if handle == self._rootdict_handle:
             entity.dxf.owner = "0"
             self.fixed_error(
                 code=AuditError.INVALID_OWNER_HANDLE,
                 message=f"Fixed invalid owner handle in root {str(self)}.",
             )
         elif entity.dxftype() == "TABLE":
             name = entity.dxf.get("name", "UNKNOWN")
             entity.dxf.owner = "0"
             self.fixed_error(
                 code=AuditError.INVALID_OWNER_HANDLE,
                 message=f"Fixed invalid owner handle for {name} table.",
             )
         else:
             self.fixed_error(
                 code=AuditError.INVALID_OWNER_HANDLE,
                 message=f"Deleted {str(entity)} entity with invalid owner "
                 f"handle #{owner_handle}.",
             )
             self.trash(doc.entitydb.get(handle))
Exemple #6
0
 def register(self, entity: DXFEntity):
     """Register resources."""
     if id(entity) not in self.packages:
         package = _ResourcePackage(entity)
         assert isinstance(entity, RTP)
         entity.dump_resources(package)
         self.packages[id(entity)] = package
Exemple #7
0
def entities():
    return [
        DXFEntity.new(handle="A"),
        DXFEntity.new(handle="D"),
        DXFEntity.new(handle="B"),
        DXFEntity.new(handle="C"),
    ]
Exemple #8
0
def test_raises_type_error_for_unsupported_objects():
    with pytest.raises(TypeError):
        make_path(DXFEntity())
    with pytest.raises(TypeError):
        make_path(Polymesh.new(dxfattribs={'flags': Polymesh.POLYMESH}))
    with pytest.raises(TypeError):
        make_path(Polymesh.new(dxfattribs={'flags': Polymesh.POLYFACE}))
Exemple #9
0
def test_safety_checks(circle):
    # invalid entities should be ignored silently
    upright(None)  # ignore None values
    upright(DXFEntity())  # ignore invalid DXF entity types
    upright(Text())  # ignore unsupported DXF entity types
    circle.destroy()
    upright(circle)  # ignore destroyed entities
    assert True is True
Exemple #10
0
 def copy_entity(self, entity: DXFEntity) -> int:
     """Copy a single entity and returns the id or 0 if the entity is
     already copied.
     """
     if id(entity) in self._copies:
         return 0
     self._copies[id(entity)] = entity.copy()
     return id(entity)
Exemple #11
0
def audit(entity: DXFEntity, doc: "Drawing") -> Auditor:
    """Setup an :class:`Auditor` object, run the audit process for `entity`
    and return result as :class:`Auditor` object.

    Args:
        entity: DXF entity to validate
        doc: bounded DXF document of `entity`

    """
    if not entity.is_alive:
        raise TypeError("Entity is destroyed.")

    # Validation of unbound entities is possible, but it is not useful
    # to validate entities against a different DXF document:
    if entity.dxf.handle is not None and not factory.is_bound(entity, doc):
        raise ValueError("Entity is bound to different DXF document.")

    auditor = Auditor(doc)
    entity.audit(auditor)
    return auditor
Exemple #12
0
def test_setting_source_block_reference_a_second_time_has_no_effect():
    e = DXFEntity()
    insert = Insert()
    e.set_source_block_reference(insert)
    e.set_source_block_reference(Insert())
    assert (e.source_block_reference is
            insert), "source block reference should not change"
Exemple #13
0
def make_primitive(e: DXFEntity,
                   max_flattening_distance=None) -> AbstractPrimitive:
    """ Factory to create path/mesh primitives. The `max_flattening_distance`
    defines the max distance between the approximation line and the original
    curve. Use `max_flattening_distance` to override the default value.

    Returns an empty primitive for unsupported entities, can be checked by
    property :attr:`is_empty`. The :attr:`path` and the :attr:`mesh` attribute
    is ``None`` and the :meth:`vertices` method yields no vertices.

    Returns an empty primitive for the :class:`~ezdxf.entities.Hatch` entity,
    see docs of the :mod:`~ezdxf.disassemble` module.

    """
    cls = _PRIMITIVE_CLASSES.get(e.dxftype(), GenericPrimitive)
    primitive = cls(e)
    if max_flattening_distance:
        primitive.max_flattening_distance = max_flattening_distance
    return primitive
Exemple #14
0
def make_primitive(entity: DXFEntity,
                   max_flattening_distance=None) -> Primitive:
    """Factory to create path/mesh primitives. The `max_flattening_distance`
    defines the max distance between the approximation line and the original
    curve. Use `max_flattening_distance` to override the default value.

    Returns an **empty primitive** for unsupported entities. The `empty` state
    of a primitive can be checked by the property :attr:`is_empty`.
    The :attr:`path` and the :attr:`mesh` attributes of an empty primitive
    are ``None`` and the :meth:`vertices` method  yields no vertices.

    .. versionchanged:: 0.17
        regular support for the :class:`~ezdxf.entities.Hatch` entity.

    """
    cls = _PRIMITIVE_CLASSES.get(entity.dxftype(), EmptyPrimitive)
    primitive = cls(entity)
    if max_flattening_distance:
        primitive.max_flattening_distance = max_flattening_distance
    return primitive
Exemple #15
0
def make_primitive(entity: DXFEntity,
                   max_flattening_distance=None) -> Primitive:
    """ Factory to create path/mesh primitives. The `max_flattening_distance`
    defines the max distance between the approximation line and the original
    curve. Use `max_flattening_distance` to override the default value.

    Returns an **empty primitive** for unsupported entities. The `empty` state
    of a primitive can be checked by the property :attr:`is_empty`.
    The :attr:`path` and the :attr:`mesh` attributes of an empty primitive
    are ``None`` and the :meth:`vertices` method  yields no vertices.

    Returns an empty primitive for the :class:`~ezdxf.entities.Hatch` entity,
    see docs of the :mod:`~ezdxf.disassemble` module. Use the this to create
    multiple primitives from the HATCH boundary paths::

        primitives = list(to_primitives([hatch_entity]))

    """
    cls = _PRIMITIVE_CLASSES.get(entity.dxftype(), EmptyPrimitive)
    primitive = cls(entity)
    if max_flattening_distance:
        primitive.max_flattening_distance = max_flattening_distance
    return primitive
Exemple #16
0
def test_set_source_block_reference():
    e = DXFEntity()
    insert = Insert()
    e.set_source_block_reference(insert)
    assert e.has_source_block_reference is True
    assert e.source_block_reference is insert
Exemple #17
0
def test_get_font_name_for_entity_without_font_usage():
    e = DXFEntity()
    assert get_font_name(e) == "txt", "should return the default font"
Exemple #18
0
def entity():
    return DXFEntity.from_text(ENTITY)
Exemple #19
0
def test_dxfentity_is_set_compatible():
    assert len({DXFEntity(), DXFEntity(), DXFEntity()}) == 3
Exemple #20
0
    def test_set_default_value(self, dxfdict):
        e = DXFEntity()
        e.dxf.handle = 'ABBA'

        dxfdict.set_default(e)
        assert dxfdict['Mozman'].dxf.handle == 'ABBA'
Exemple #21
0
def test_delete_missing_source_block_reference_without_exception():
    e = DXFEntity()
    e.del_source_block_reference()
    assert True is True
Exemple #22
0
 def test_raise_type_error_for_unsupported_types(self):
     with pytest.raises(TypeError):
         is_text_vertical_stacked(DXFEntity())
 def dxfdict(self):
     d = DictionaryWithDefault.from_text(DEFAULT_DICT, doc=MockDoc())
     d._default = DXFEntity()
     d._default.dxf.handle = "FEFE"
     return d
    def test_set_default_value(self, dxfdict):
        e = DXFEntity()
        e.dxf.handle = "ABBA"

        dxfdict.set_default(e)
        assert dxfdict["Mozman"].dxf.handle == "ABBA"
Exemple #25
0
def test_source_block_reference_is_none_for_a_new_entity():
    e = DXFEntity()
    assert e.has_source_block_reference is False
    assert e.source_block_reference is None
Exemple #26
0
def test_delete_missing_source_of_copy_without_exception():
    e = DXFEntity()
    e.del_source_of_copy()
    assert True is True
Exemple #27
0
def test_uuid():
    e1 = DXFEntity()
    e2 = DXFEntity()
    assert e1.dxf.handle == e2.dxf.handle, "can't distinguish by handle"
    assert e1.uuid != e2.uuid, "can distinguish by uuid"
Exemple #28
0
def test_source_of_copy_is_none_for_a_new_entity():
    e = DXFEntity()
    assert e.source_of_copy is None
Exemple #29
0
def test_set_source_of_copy():
    e = DXFEntity()
    e.set_source_of_copy(e)
    assert e.source_of_copy is e
Exemple #30
0
def test_setting_source_block_reference_twice_without_exception():
    e = DXFEntity()
    e.set_source_block_reference(Insert())
    e.set_source_block_reference(Insert())
    assert True is True