def __init__(self, tagger: Iterable['DXFTag']): """ Build a new DXF drawing from a steam of DXF tags. Args: tagger: generator or list of DXF tags as DXFTag() objects """ def get_header(sections: 'SectionDict') -> 'SectionType': from .sections.header import HeaderSection header_entities = sections.get('HEADER', [None])[0] # all tags in the first DXF structure entity return HeaderSection(header_entities) self.tracker = Tracker() self._dimension_renderer = DimensionRenderer() # set DIMENSION rendering engine self._groups = None # type: GroupManager # read only self._materials = None # type: MaterialManager # read only self._mleader_styles = None # type: MLeaderStyleManager # read only self._mline_styles = None # type: MLineStyleManager # read only self._acad_compatible = True # will generated DXF file compatible with AutoCAD self._acad_incompatibility_reason = set() # avoid multiple warnings for same reason self.filename = None # type: str # read/write self.entitydb = EntityDB() # read only sections = load_dxf_structure(tagger) # load complete DXF entity structure # create section HEADER header = get_header(sections) self.dxfversion = header.get('$ACADVER', 'AC1009') # type: str # read only self.dxffactory = dxffactory(self) # read only, requires self.dxfversion self.encoding = toencoding(header.get('$DWGCODEPAGE', 'ANSI_1252')) # type: str # read/write # get handle seed seed = header.get('$HANDSEED', str(self.entitydb.handles)) # type: str # setup handles self.entitydb.handles.reset(seed) # store all necessary DXF entities in the drawing database fill_database(self.entitydb, sections, dxfversion=self.dxfversion) # create sections: TABLES, BLOCKS, ENTITIES, CLASSES, OBJECTS self.sections = Sections(sections, drawing=self, header=header) if self.dxfversion > 'AC1009': self.rootdict = self.objects.rootdict self.objects.setup_objects_management_tables(self.rootdict) # create missing tables if self.dxfversion in ('AC1012', 'AC1014'): # releases R13 and R14 repair.upgrade_to_ac1015(self) # some applications don't setup properly the model and paper space layouts repair.setup_layouts(self) self._groups = self.objects.groups() self._materials = self.objects.materials() self._mleader_styles = self.objects.mleader_styles() self._mline_styles = self.objects.mline_styles() else: # dxfversion <= 'AC1009' do cleanup work, before building layouts if self.dxfversion < 'AC1009': # legacy DXF version repair.upgrade_to_ac1009(self) # upgrade to DXF format AC1009 (DXF R12) repair.cleanup_r12(self) # ezdxf puts automatically handles into all entities added to the entities database # write R12 without handles, by setting $HANDLING = 0 self.header['$HANDLING'] = 1 # write handles by default self.layouts = self.dxffactory.get_layouts()
def test_add_tags(): db = EntityDB() db.add_tags(ENTITY) assert 'FFFF' in db
def db(): db = EntityDB() db['0'] = ENTITY return db
def setUp(self): self.db = EntityDB() self.db[0] = 'TEST'
def space(): return EntitySpace(EntityDB())
def __init__(self, version): self.dxfversion = version self.entitydb = EntityDB() self.dxffactory = dxffactory(self)
def db(): db = EntityDB() db[0] = 'TEST' return db