示例#1
0
def test_create_db_entry(doc):
    e = factory.create_db_entry('POINT', {}, doc)
    assert e.doc is doc
    assert e.dxf.handle is not None, 'should have a handle'
    assert e.dxf.handle in doc.entitydb, 'should be stored in the entity database'
    assert e.dxf.owner is None, 'should not be linked to a layout or owner'
    assert e.is_virtual is False, 'is not a virtual entity'
示例#2
0
 def new_seqend(self):
     """ Create and bind new SEQEND. (internal API) """
     attribs = {'layer': self.dxf.layer}
     if self.doc:
         seqend = factory.create_db_entry('SEQEND', attribs, self.doc)
     else:
         seqend = factory.new('SEQEND', attribs)
     self.link_seqend(seqend)
示例#3
0
def test_unbind_bound_entity(doc):
    e = factory.create_db_entry('POINT', {}, doc)
    doc.modelspace().add_entity(e)
    factory.unbind(e)
    assert e.is_alive, 'should not be destroyed'
    assert e.is_virtual, 'should be virtual entity'
    assert e.doc is None
    assert e.dxf.owner is None
    assert e.dxf.handle is None
示例#4
0
    def new(self,
            name: str,
            base_point: Sequence[float] = (0, 0),
            dxfattribs: dict = None) -> 'BlockLayout':
        """ Create and add a new :class:`~ezdxf.layouts.BlockLayout`, `name`
        is the BLOCK name, `base_point` is the insertion point of the BLOCK.
        """
        block_record = self.doc.block_records.new(name)

        dxfattribs = dxfattribs or {}
        dxfattribs['owner'] = block_record.dxf.handle
        dxfattribs['name'] = name
        dxfattribs['base_point'] = base_point
        head = factory.create_db_entry('BLOCK', dxfattribs, self.doc)
        tail = factory.create_db_entry('ENDBLK',
                                       {'owner': block_record.dxf.handle},
                                       doc=self.doc)
        block_record.set_block(head, tail)
        return self.add(block_record)
示例#5
0
文件: table.py 项目: billhu0228/ezdxf
    def new_entry(self, dxfattribs: dict) -> 'DXFEntity':
        """ Create new table-entry of type 'self._dxfname', and add new entry
        to table.

        Does not check if an entry dxfattribs['name'] already exists!
        Duplicate entries are possible for Viewports.
        """
        entry = factory.create_db_entry(self._head.dxf.name, dxfattribs, self.doc)
        self._append(entry)
        return entry
示例#6
0
    def new_entity(self, _type: str, dxfattribs: dict) -> 'DXFObject':
        """ Create new DXF object, add it to the entity database and to the entity space.

        Args:
             _type: DXF type like `DICTIONARY`
             dxfattribs: DXF attributes as dict

        (internal API)
        """
        dxf_entity = factory.create_db_entry(_type, dxfattribs, self.doc)
        self._entity_space.add(dxf_entity)
        return dxf_entity
示例#7
0
    def new_entry(self, dxfattribs: dict) -> T:
        """Create and add new table-entry of type 'self.entry_dxftype'.

        Does not check if an entry dxfattribs['name'] already exists!
        Duplicate entries are possible for Viewports.
        """
        assert self.doc is not None, "valid DXF document expected"
        entry = cast(
            T, factory.create_db_entry(self.TABLE_TYPE, dxfattribs, self.doc)
        )
        self._append(entry)
        return entry
def test_do_not_purge_used_dimension(doc):
    # DIMENSION (and ACAD_TABLE) block are not referenced by explicit INSERT
    # entity.
    dimension = factory.create_db_entry(
        'DIMENSION',
        dxfattribs={'geometry': '*D01'},
        doc=doc,
    )
    msp = doc.modelspace()
    msp.add_entity(dimension)
    doc.blocks.new('*D01')
    doc.blocks.purge()
    assert '*D01' in doc.blocks
示例#9
0
    def _reconstruct_orphaned_block_records(self):
        """ Find BLOCK_RECORD entries without block definition in the blocks
        section and create block definitions for this orphaned block records.

        """
        for block_record in self.block_records:  # type: BlockRecord
            if block_record.block is None:
                block = factory.create_db_entry(
                    'BLOCK',
                    dxfattribs={
                        'name': block_record.dxf.name,
                        'base_point': (0, 0, 0),
                    },
                    doc=self.doc,
                )
                endblk = factory.create_db_entry(
                    'ENDBLK',
                    dxfattribs={},
                    doc=self.doc,
                )
                block_record.set_block(block, endblk)
                self.add(block_record)
示例#10
0
    def new(
        self,
        name: str,
        base_point: Vertex = NULLVEC,
        dxfattribs: dict = None,
    ) -> "BlockLayout":
        """Create and add a new :class:`~ezdxf.layouts.BlockLayout`, `name`
        is the BLOCK name, `base_point` is the insertion point of the BLOCK.
        """
        assert self.doc is not None
        block_record = cast(BlockRecord, self.doc.block_records.new(name))

        dxfattribs = dxfattribs or {}
        dxfattribs["owner"] = block_record.dxf.handle
        dxfattribs["name"] = name
        dxfattribs["base_point"] = Vec3(base_point)
        head = factory.create_db_entry("BLOCK", dxfattribs, self.doc)
        tail = factory.create_db_entry("ENDBLK",
                                       {"owner": block_record.dxf.handle},
                                       doc=self.doc)
        block_record.set_block(head, tail)  # type: ignore
        return self.add(block_record)
示例#11
0
文件: dxfgfx.py 项目: mhenr18/ezdxf
    def _new_compound_entity(self, type_: str,
                             dxfattribs: dict) -> 'DXFGraphic':
        """ Create and bind  new entity with same layout settings as `self`.

        Used by INSERT & POLYLINE to create appended DXF entities, don't use it
        to create new standalone entities.

        (internal API)
        """
        dxfattribs = dxfattribs or {}

        # if layer is not deliberately set, set same layer as creator entity,
        # at least VERTEX should have the same layer as the POLYGON entity.
        # Don't know if that is also important for the ATTRIB & INSERT entity.
        if 'layer' not in dxfattribs:
            dxfattribs['layer'] = self.dxf.layer
        if self.doc:
            entity = factory.create_db_entry(type_, dxfattribs, self.doc)
        else:
            entity = factory.new(type_, dxfattribs)
        entity.dxf.owner = self.dxf.owner
        entity.dxf.paperspace = self.dxf.paperspace
        return entity