entityspace.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Purpose: entity space
  2. # Created: 13.03.2011
  3. # Copyright (C) 2011, Manfred Moitzi
  4. # License: MIT License
  5. from typing import TYPE_CHECKING
  6. if TYPE_CHECKING: # import forward declarations
  7. from ezdxf.eztypes import EntityDB, ExtendedTags, TagWriter, DXFEntity
  8. class EntitySpace(list):
  9. """
  10. An EntitySpace is a collection of drawing entities.
  11. The ENTITY section is such an entity space, but also blocks.
  12. The EntitySpace stores only handles to the drawing entity database.
  13. """
  14. def __init__(self, entitydb: 'EntityDB'):
  15. self._entitydb = entitydb
  16. def get_tags_by_handle(self, handle: str) -> 'ExtendedTags':
  17. return self._entitydb[handle]
  18. def store_tags(self, tags: 'ExtendedTags') -> str:
  19. handle = tags.get_handle()
  20. self.append(handle)
  21. return handle
  22. def write(self, tagwriter: 'TagWriter') -> None:
  23. for handle in self:
  24. # write linked entities
  25. while handle is not None:
  26. tags = self._entitydb[handle]
  27. tagwriter.write_tags(tags)
  28. handle = tags.link
  29. def delete_entity(self, entity: 'DXFEntity') -> None:
  30. # do not delete database objects - entity space just manage handles
  31. self.remove(entity.dxf.handle)
  32. def delete_all_entities(self) -> None:
  33. # do not delete database objects - entity space just manage handles
  34. del self[:]
  35. def add_handle(self, handle: str) -> None:
  36. self.append(handle)