示例#1
0
def test_load_section():
    doc = ezdxf.new('R2000')
    ent = load_entities(TESTOBJECTS, 'OBJECTS')

    section = ObjectsSection(doc, ent)
    assert len(section) == 6
    assert section[0].dxftype() == 'DICTIONARY'
def test_load_section():
    doc = ezdxf.new("R2000")
    ent = load_entities(TESTOBJECTS, "OBJECTS")

    section = ObjectsSection(doc, ent)
    assert len(section) == 6
    assert section[0].dxftype() == "DICTIONARY"
示例#3
0
 def test_empty_section(self):
     section = ObjectsSection(Tags.from_text(EMPTYSEC), self.dwg)
     stream = StringIO()
     section.write(stream)
     result = stream.getvalue()
     stream.close()
     self.assertEqual(EMPTYSEC, result)
示例#4
0
def test_empty_section():
    ent = load_section(EMPTYSEC, 'OBJECTS')
    dwg = DrawingProxy('AC1015')
    section = ObjectsSection(ent, dwg)
    stream = StringIO()
    section.write(TagWriter(stream))
    result = stream.getvalue()
    stream.close()
    assert EMPTYSEC == result
示例#5
0
def test_empty_section():
    ent = load_section(EMPTYSEC, 'OBJECTS')
    dwg = ezdxf.new('R2000')
    section = ObjectsSection(ent, dwg)
    stream = StringIO()
    section.write(TagWriter(stream))
    result = stream.getvalue()
    stream.close()
    assert EMPTYSEC == result
示例#6
0
文件: drawing.py 项目: vshu3000/ezdxf
 def _setup(self):
     self.header = HeaderSection.new()
     self.classes = ClassesSection(self)
     self.tables = TablesSection(self)
     self.blocks = BlocksSection(self)
     self.entities = EntitySection(self)
     self.objects = ObjectsSection(self)
     self.acdsdata = AcDsDataSection(self)  # AcDSData section is not supported for new drawings
     self.rootdict = self.objects.rootdict
     self.objects.setup_objects_management_tables(self.rootdict)  # create missing tables
     self.layouts = Layouts.setup(self)
     self._finalize_setup()
示例#7
0
 def setUp(self):
     self.objects = ObjectsSection(Tags.from_text(EMPTYSEC), DXF_DRAWING)
     DXF_DRAWING.sections._sections[
         'objects'] = self.objects  # reset objects section
示例#8
0
    def _load_section_dict(self, sections: loader.SectionDict) -> None:
        """ Internal API to load a DXF document from a section dict. """
        self.is_loading = True
        # Create header section:
        # All header tags are the first DXF structure entity
        header_entities = sections.get('HEADER', [None])[0]
        if header_entities is None:
            # Create default header, files without header are by default DXF R12
            self.header = HeaderSection.new(dxfversion=DXF12)
        else:
            self.header = HeaderSection.load(header_entities)

        self._dxfversion: str = self.header.get('$ACADVER', DXF12)

        # Store original DXF version of loaded file.
        self._loaded_dxfversion = self._dxfversion

        # Content encoding:
        self.encoding = toencoding(self.header.get('$DWGCODEPAGE',
                                                   'ANSI_1252'))

        # Set handle seed:
        seed: str = self.header.get('$HANDSEED', str(self.entitydb.handles))
        self.entitydb.handles.reset(_validate_handle_seed(seed))

        # Store all necessary DXF entities in the entity database:
        loader.load_and_bind_dxf_content(sections, self)

        # End of 1. loading stage, all entities of the DXF file are
        # stored in the entity database.

        # Create sections:
        self.classes = ClassesSection(self, sections.get('CLASSES', None))
        self.tables = TablesSection(self, sections.get('TABLES', None))

        # Create *Model_Space and *Paper_Space BLOCK_RECORDS
        # BlockSection setup takes care about the rest:
        self._create_required_block_records()

        # At this point all table entries are required:
        self.blocks = BlocksSection(self, sections.get('BLOCKS', None))
        self.entities = EntitySection(self, sections.get('ENTITIES', None))
        self.objects = ObjectsSection(self, sections.get('OBJECTS', None))

        # only DXF R2013+
        self.acdsdata = AcDsDataSection(self, sections.get('ACDSDATA', None))

        # Store unmanaged sections as raw tags:
        for name, data in sections.items():
            if name not in const.MANAGED_SECTIONS:
                self.stored_sections.append(StoredSection(data))

        # Objects section is not initialized!
        self._2nd_loading_stage()

        # DXF version upgrades:
        if self.dxfversion < DXF12:
            logger.info('DXF version upgrade to DXF R12.')
            self.dxfversion = DXF12

        if self.dxfversion == DXF12:
            self.tables.create_table_handles()

        if self.dxfversion in (DXF13, DXF14):
            logger.info('DXF version upgrade to DXF R2000.')
            self.dxfversion = DXF2000
            self.create_all_arrow_blocks()

        # Objects section setup:
        self.rootdict = self.objects.rootdict
        # Create missing management tables (DICTIONARY):
        self.objects.setup_objects_management_tables(self.rootdict)

        # Setup modelspace- and paperspace layouts:
        self.layouts = Layouts.load(self)

        # Additional work is common to the new and load process:
        self.is_loading = False
        self._finalize_setup()
    def _load(self, tagger: Iterable['DXFTag']):
        sections = load_dxf_structure(
            tagger)  # load complete DXF entity structure
        try:  # discard section THUMBNAILIMAGE
            del sections['THUMBNAILIMAGE']
        except KeyError:
            pass
        # -----------------------------------------------------------------------------------
        # create header section:
        # all header tags are the first DXF structure entity
        header_entities = sections.get('HEADER', [None])[0]
        if header_entities is None:
            # create default header, files without header are by default DXF R12
            self.header = HeaderSection.new(dxfversion=DXF12)
        else:
            self.header = HeaderSection.load(header_entities)
        # -----------------------------------------------------------------------------------
        # missing $ACADVER defaults to DXF R12
        self._dxfversion = self.header.get('$ACADVER', DXF12)  # type: str
        self._loaded_dxfversion = self._dxfversion  # save dxf version of loaded file
        self.encoding = toencoding(self.header.get(
            '$DWGCODEPAGE', 'ANSI_1252'))  # type: str # read/write
        # get handle seed
        seed = self.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(sections, self.dxffactory)
        # all handles used in the DXF file are known at this point
        # -----------------------------------------------------------------------------------
        # create sections:
        self.classes = ClassesSection(self, sections.get('CLASSES', None))
        self.tables = TablesSection(self, sections.get('TABLES', None))
        # create *Model_Space and *Paper_Space BLOCK_RECORDS
        # BlockSection setup takes care about the rest
        self._create_required_block_records()
        # table records available
        self.blocks = BlocksSection(self, sections.get('BLOCKS', None))

        self.entities = EntitySection(self, sections.get('ENTITIES', None))
        self.objects = ObjectsSection(self, sections.get('OBJECTS', None))
        # only valid for DXF R2013 and later
        self.acdsdata = AcDsDataSection(self, sections.get('ACDSDATA', None))

        for name, data in sections.items():
            if name not in MANAGED_SECTIONS:
                self.stored_sections.append(StoredSection(data))
        # -----------------------------------------------------------------------------------
        if self.dxfversion < DXF12:
            # upgrade to DXF R12
            logger.info('Upgrading drawing to DXF R12.')
            self.dxfversion = DXF12

        # DIMSTYLE: ezdxf uses names for blocks, linetypes and text style as internal data, handles are set at export
        # requires BLOCKS and TABLES section!
        self.tables.resolve_dimstyle_names()

        if self.dxfversion == DXF12:
            # TABLE requires in DXF12 no handle and has no owner tag, but DXF R2000+, requires a TABLE with handle
            # and each table entry has an owner tag, pointing to the TABLE entry
            self.tables.create_table_handles()

        if self.dxfversion in (DXF13, DXF14):
            # upgrade to DXF R2000
            self.dxfversion = DXF2000

        self.rootdict = self.objects.rootdict
        self.objects.setup_objects_management_tables(
            self.rootdict)  # create missing tables

        self.layouts = Layouts.load(self)
        self._finalize_setup()
示例#10
0
def objects(dwg):
    objects = ObjectsSection(load_section(EMPTYSEC, 'OBJECTS'), dwg)
    dwg.sections._sections['OBJECTS'] = objects   # reset objects load_section
    return objects
示例#11
0
 def setUp(self):
     self.dwg = DrawingProxy('AC1015')
     self.section = ObjectsSection(Tags.from_text(TESTOBJECTS), self.dwg)
示例#12
0
def section():
    dwg = DrawingProxy('AC1015')
    return ObjectsSection(load_section(TESTOBJECTS, 'OBJECTS', dwg.entitydb), dwg)
示例#13
0
def section():
    dwg = ezdxf.new('R2000')
    return ObjectsSection(load_section(TESTOBJECTS, 'OBJECTS', dwg.entitydb), dwg)