Skip to content

Commit

Permalink
release v0.8.1
Browse files Browse the repository at this point in the history
closes #13
added ATTDEF management methods to BlockLayout (has_attdef, get_attdef, get_attdef_text)
added (read/write) properties to ATTDEF/ATTRIB for setting flags (is_const, is_invisible, is_verify, is_preset)
  • Loading branch information
mozman committed Apr 6, 2017
1 parent 47132cc commit d189a5d
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 47 deletions.
6 changes: 4 additions & 2 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
News
====

Version 0.8.1
Version 0.8.1 - 2017-04-06

* added support for constant ATTRIB/ATTDEF to the INSERT (block reference) entity
* NEW: added support for constant ATTRIB/ATTDEF to the INSERT (block reference) entity
* NEW: added ATTDEF management methods to BlockLayout (has_attdef, get_attdef, get_attdef_text)
* NEW: added (read/write) properties to ATTDEF/ATTRIB for setting flags (is_const, is_invisible, is_verify, is_preset)

Version 0.8.0 - 2017-03-28

Expand Down
32 changes: 32 additions & 0 deletions docs/source/blocks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ field_length R12 just relevant to CAD programs for validating user

DXF attributes namespace, read/write DXF attributes, like :code:`object.dxf.layer = 'MyLayer'`

.. attribute:: Attdef.is_invisibe

(read/write) Attribute is invisible (does not appear).

.. attribute:: Attdef.is_const

(read/write) This is a constant attribute.

.. attribute:: Attdef.is_verify

(read/write) Verification is required on input of this attribute. (CAD application feature)

.. attribute:: Attdef.is_preset

(read/write) No prompt during insertion. (CAD application feature)

.. method:: Attdef.get_pos()

see method :meth:`Text.get_pos`.
Expand Down Expand Up @@ -211,6 +227,22 @@ text_generation_flag R12 text generation flags (int)

DXF attributes namespace, read/write DXF attributes, like :code:`object.dxf.layer = 'MyLayer'`

.. attribute:: Attrib.is_invisibe

(read/write) Attribute is invisible (does not appear).

.. attribute:: Attrib.is_const

(read/write) This is a constant attribute.

.. attribute:: Attrib.is_verify

(read/write) Verification is required on input of this attribute. (CAD application feature)

.. attribute:: Attrib.is_preset

(read/write) No prompt during insertion. (CAD application feature)

.. method:: Attrib.get_pos()

see method :meth:`Text.get_pos`.
Expand Down
14 changes: 14 additions & 0 deletions docs/source/layouts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,17 @@ BlockLayout
.. method:: BlockLayout.attdefs()

Iterator for included :class:`Attdef` entities.

.. method:: BlockLayout.has_attdef(tag)

Returns `True` if an attdef `tag` exists else `False`.

.. method:: BlockLayout.get_attdef(tag)

Get the attribute definition object :class:`Attdef` with :code:`object.dxf.tag == tag`, returns
:code:`None` if not found.

.. method:: BlockLayout.get_attdef_text(tag, default=None)

Get content text for attdef `tag` as string or return `default` if no attdef `tag` exists.

88 changes: 77 additions & 11 deletions ezdxf/legacy/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@ class SeqEnd(GraphicEntity):
'paperspace': DXFAttr(67, default=0),
}))

_ATTDEF_TPL = """ 0
ATTDEF
_ATTRIB_TPL = """ 0
ATTRIB
5
0
8
Expand All @@ -584,8 +584,6 @@ class SeqEnd(GraphicEntity):
1.0
1
DEFAULTTEXT
3
PROMPTTEXT
2
TAG
70
Expand Down Expand Up @@ -615,13 +613,19 @@ class SeqEnd(GraphicEntity):
"""


class Attdef(Text):
TEMPLATE = ClassifiedTags.from_text(_ATTDEF_TPL)
def _set_flag_state(flags, mask, state):
if bool(state):
return flags | mask
else:
return flags & ~mask


class Attrib(Text):
TEMPLATE = ClassifiedTags.from_text(_ATTRIB_TPL)
DXFATTRIBS = make_attribs({
'insert': DXFAttr(10, xtype='Point2D/3D'),
'height': DXFAttr(40),
'text': DXFAttr(1),
'prompt': DXFAttr(3),
'tag': DXFAttr(2),
'flags': DXFAttr(70),
'field_length': DXFAttr(73, default=0),
Expand All @@ -635,8 +639,66 @@ class Attdef(Text):
'align_point': DXFAttr(11, xtype='Point2D/3D'),
})

_ATTRIB_TPL = """ 0
ATTRIB
@property
def is_const(self):
"""
This is a constant attribute.
"""
return self.dxf.flags & const.ATTRIB_CONST

@is_const.setter
def is_const(self, state):
"""
This is a constant attribute.
"""
self.dxf.flags = _set_flag_state(self.dxf.flags, const.ATTRIB_CONST, state)

@property
def is_invisible(self):
"""
Attribute is invisible (does not appear).
"""
return self.dxf.flags & const.ATTRIB_INVISIBLE

@is_invisible.setter
def is_invisible(self, state):
"""
Attribute is invisible (does not appear).
"""
self.dxf.flags = _set_flag_state(self.dxf.flags, const.ATTRIB_INVISIBLE, state)

@property
def is_verify(self):
"""
Verification is required on input of this attribute. (CAD application feature)
"""
return self.dxf.flags & const.ATTRIB_VERIFY

@is_verify.setter
def is_verify(self, state):
"""
Verification is required on input of this attribute. (CAD application feature)
"""
self.dxf.flags = _set_flag_state(self.dxf.flags, const.ATTRIB_VERIFY, state)


@property
def is_preset(self):
"""
No prompt during insertion. (CAD application feature)
"""
return self.dxf.flags & const.ATTRIB_IS_PRESET

@is_preset.setter
def is_preset(self, state):
"""
No prompt during insertion. (CAD application feature)
"""
self.dxf.flags = _set_flag_state(self.dxf.flags, const.ATTRIB_IS_PRESET, state)


_ATTDEF_TPL = """ 0
ATTDEF
5
0
8
Expand All @@ -651,6 +713,8 @@ class Attdef(Text):
1.0
1
DEFAULTTEXT
3
PROMPTTEXT
2
TAG
70
Expand Down Expand Up @@ -680,12 +744,13 @@ class Attdef(Text):
"""


class Attrib(Text):
TEMPLATE = ClassifiedTags.from_text(_ATTRIB_TPL)
class Attdef(Attrib):
TEMPLATE = ClassifiedTags.from_text(_ATTDEF_TPL)
DXFATTRIBS = make_attribs({
'insert': DXFAttr(10, xtype='Point2D/3D'),
'height': DXFAttr(40),
'text': DXFAttr(1),
'prompt': DXFAttr(3),
'tag': DXFAttr(2),
'flags': DXFAttr(70),
'field_length': DXFAttr(73, default=0),
Expand All @@ -699,6 +764,7 @@ class Attrib(Text):
'align_point': DXFAttr(11, xtype='Point2D/3D'),
})


_POLYLINE_TPL = """ 0
POLYLINE
5
Expand Down

0 comments on commit d189a5d

Please sign in to comment.