def __init__(self, dxfversion=DXF2013): self.entitydb = EntityDB() target_dxfversion = dxfversion.upper() self._dxfversion: str = const.acad_release_to_dxf_version.get( target_dxfversion, target_dxfversion) if self._dxfversion not in const.versions_supported_by_new: raise const.DXFVersionError( f'Unsupported DXF version "{self.dxfversion}".') # Store original dxf version if loaded (and maybe converted R13/14) # from file. self._loaded_dxfversion: Optional[str] = None # Status flag which is True while loading content from a DXF file: self.is_loading = False self.encoding: str = "cp1252" # read/write self.filename: Optional[str] = None # Reason for using "type: ignore". # I won't use "Optional" for the following attributes because these # objects are required, just not yet! Setting up an empty DXF Document # is not necessary if the document is read from the file system, # see class-methods new() and read(). # named objects dictionary self.rootdict: "Dictionary" = None # type: ignore # DXF sections self.header: HeaderSection = None # type: ignore self.classes: ClassesSection = None # type: ignore self.tables: TablesSection = None # type: ignore self.blocks: BlocksSection = None # type: ignore self.entities: EntitySection = None # type: ignore self.objects: ObjectsSection = None # type: ignore # DXF R2013 and later self.acdsdata: AcDsDataSection = None # type: ignore self.stored_sections: List[StoredSection] = [] self.layouts: Layouts = None # type: ignore self.groups: GroupCollection = None # type: ignore self.materials: MaterialCollection = None # type: ignore self.mleader_styles: MLeaderStyleCollection = None # type: ignore self.mline_styles: MLineStyleCollection = None # type: ignore # Set to False if the generated DXF file will be incompatible to AutoCAD self._acad_compatible = True # Store reasons for AutoCAD incompatibility: self._acad_incompatibility_reason = set() # DIMENSION rendering engine can be replaced by a custom Dimension # render: see property Drawing.dimension_renderer self._dimension_renderer = DimensionRenderer() # Some fixes can't be applied while the DXF document is not fully # initialized, store this fixes as callable object: self._post_init_commands: List[Callable] = [] # Don't create any new entities here: # New created handles could collide with handles loaded from DXF file. assert len(self.entitydb) == 0
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 __init__(self, dxfversion=DXF2013): self.entitydb = EntityDB() self.dxffactory = EntityFactory(self) self.tracker = Tracker() target_dxfversion = dxfversion.upper() self._dxfversion: str = acad_release_to_dxf_version.get( target_dxfversion, target_dxfversion) if self._dxfversion not in versions_supported_by_new: raise DXFVersionError( f'Unsupported DXF version "{self.dxfversion}".') # Store original dxf version if loaded (and maybe converted R13/14) from file. self._loaded_dxfversion: Optional[str] = None self.encoding: str = 'cp1252' # read/write self.filename: Optional[str] = None # named objects dictionary self.rootdict: 'Dictionary' = None # DXF sections self.header: HeaderSection = None self.classes: ClassesSection = None self.tables: TablesSection = None self.blocks: BlocksSection = None self.entities: EntitySection = None self.objects: ObjectsSection = None # DXF R2013 and later self.acdsdata: AcDsDataSection = None self.stored_sections = [] self.layouts: Layouts = None self.groups: GroupCollection = None self.materials: MaterialCollection = None self.mleader_styles: MLeaderStyleCollection = None self.mline_styles: MLineStyleCollection = None self._acad_compatible = True # will generated DXF file compatible with AutoCAD self._dimension_renderer = DimensionRenderer( ) # set DIMENSION rendering engine self._acad_incompatibility_reason = set( ) # avoid multiple warnings for same reason # Don't create any new entities here: # New created handles could collide with handles loaded from DXF file. assert len(self.entitydb) == 0
def __init__(self, dxfversion=DXF2013): self.entitydb = EntityDB() self.dxffactory = EntityFactory(self) self.tracker = Tracker() # still required # Targeted DXF version, but drawing could be exported as another DXF version. # If target version is set, it is possible to warn user, if they try to use unsupported features, where they # use it and not at exporting, where the location of the code who created that features is not known. target_dxfversion = dxfversion.upper() self._dxfversion = acad_release_to_dxf_version.get( target_dxfversion, target_dxfversion) self._loaded_dxfversion = None # if loaded from file, store original dxf version self.encoding = 'cp1252' self.filename = None # type: str # read/write # named objects dictionary self.rootdict = None # type: Dictionary # DXF sections self.header = None # type: HeaderSection self.classes = None # type: ClassesSection self.tables = None # type: TablesSection self.blocks = None # type: BlocksSection self.entities = None # type: EntitySection self.objects = None # type: ObjectsSection # DXF R2013 and later self.acdsdata = None # type: AcDsDataSection self.stored_sections = [] self.layouts = None # type: Layouts self.groups = None # type: GroupCollection # read only self.materials = None # type: MaterialCollection # read only self.mleader_styles = None # type: MLeaderStyleCollection # read only self.mline_styles = None # type: MLineStyleCollection # read only self._acad_compatible = True # will generated DXF file compatible with AutoCAD self._dimension_renderer = DimensionRenderer( ) # set DIMENSION rendering engine self._acad_incompatibility_reason = set( ) # avoid multiple warnings for same reason # Don't create any new entities here: # New created handles could collide with handles loaded from DXF file. assert len(self.entitydb) == 0