Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
1.0
42
1.0
43
1.0
50
0.0
280
2
281
100
282
0
"""
underlay_subclass = DefSubclass('AcDbUnderlayReference', {
'underlay_def': DXFAttr(340), # Hard reference to underlay definition object
'insert': DXFAttr(10, xtype=XType.point3d),
'scale_x': DXFAttr(41, default=1.), # scale x factor
'scale_y': DXFAttr(42, default=1.), # scale y factor
'scale_z': DXFAttr(43, default=1.), # scale z factor
'rotation': DXFAttr(50, default=0.), # rotation angle in degrees?
'extrusion': DXFAttr(210, xtype=XType.point3d),
'flags': DXFAttr(280, default=0), # Underlay display properties:
# 1 = Clipping is on
# 2 = Underlay is on
# 4 = Monochrome
# 8 = Adjust for background
'contrast': DXFAttr(281, default=100), # Contrast value (20-100; default = 100)
'fade': DXFAttr(282, default=0), # Fade value (0-80; default = 0)
})
'halign': DXFAttr(72, default=0, optional=True),
# 0 = Left
# 2 = Right
# 3 = Aligned (if vertical alignment = 0)
# 4 = Middle (if vertical alignment = 0)
# 5 = Fit (if vertical alignment = 0)
# This value is meaningful only if the value of a 72 or 73 group is nonzero (if the justification is anything other
# than baseline/left)
'align_point': DXFAttr(11, xtype=XType.point3d, optional=True), # Second alignment point (in OCS) (optional)
'thickness': DXFAttr(39, default=0, optional=True), # Thickness (optional)
# Extrusion direction (optional)
'extrusion': DXFAttr(210, xtype=XType.point3d, default=Vector(0, 0, 1), optional=True),
})
acdb_text2 = DefSubclass('AcDbText', {
'valign': DXFAttr(73, default=0, optional=True) # Vertical text justification type (optional)
# 0 = Baseline
# 1 = Bottom
# 2 = Middle
# 3 = Top
})
@register_entity
class Text(DXFGraphic):
""" DXF TEXT entity """
DXFTYPE = 'TEXT'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_text, acdb_text2)
# horizontal align values
LEFT = 0
CENTER = 1
'oblique_angle': DXFAttr(52, default=0, optional=True),
# Linear dimension types with an oblique angle have an optional group
# code 52. When added to the rotation angle of the linear dimension (group code 50), it gives the angle of the
# extension lines (DXF reference error: false subclass AcDbAlignedDimension)
'text_rotation': DXFAttr(53, default=0, optional=True),
# The optional group code 53 is the rotation angle of the dimension
# text away from its default orientation (the direction of the dimension line) (optional)
'horizontal_direction': DXFAttr(51, default=0, optional=True),
# All dimension types have an optional 51 group code, which
# indicates the horizontal direction for the dimension entity. The dimension entity determines the orientation of
# dimension text and lines for horizontal, vertical, and rotated linear dimensions. This group value is the negative
# of the angle between the OCS X axis and the UCS X axis. It is always in the XY plane of the OCS
'extrusion': DXFAttr(210, xtype=XType.point3d, default=Vector(0, 0, 1), optional=True),
})
acdb_dimension_dummy = DefSubclass('AcDbDimensionDummy', {
'defpoint2': DXFAttr(13, xtype=XType.point3d, default=Vector(0, 0, 0)),
# Definition point for linear and angular dimensions (in WCS)
'defpoint3': DXFAttr(14, xtype=XType.point3d, default=Vector(0, 0, 0)),
# Definition point for linear and angular dimensions (in WCS)
# The defpoint2 (13,23,33) specifies the start point of the first extension line and
# the defpoint3 (14,24,34) specifies the start point of the second extension line.
# Defpoint (10,20,30) specifies the dimension line location. The text_midpoint (11,21,31)
# specifies the midpoint of the dimension text.
'angle': DXFAttr(50, default=0), # Angle of rotated, horizontal, or vertical dimensions
'defpoint4': DXFAttr(15, xtype=XType.point3d, default=Vector(0, 0, 0)),
# Definition point for diameter, radius, and angular dimensions (in WCS)
'leader_length': DXFAttr(40), # Leader length for radius and diameter dimensions
'defpoint5': DXFAttr(16, xtype=XType.point3d, default=Vector(0, 0, 0)),
# Point defining dimension arc for angular dimensions (in OCS)
# The defpoint2 (13,23,33) and defpoint3 (14,24,34) specify the endpoints of the line used to determine the first
# extension line. Defpoint (10,20,30) and defpoint4 (15,25,35) specify the endpoints of the line used to determine
# License: MIT License
# Created 2019-02-15
from typing import TYPE_CHECKING
from ezdxf.math import Vector, UCS
from ezdxf.lldxf.attributes import DXFAttr, DXFAttributes, DefSubclass, XType
from ezdxf.lldxf.const import DXF12, SUBCLASS_MARKER
from .dxfentity import base_class, SubclassProcessor
from .dxfgfx import DXFGraphic, acdb_entity
from .factory import register_entity
if TYPE_CHECKING:
from ezdxf.eztypes import TagWriter, DXFNamespace
__all__ = ['Line']
acdb_line = DefSubclass('AcDbLine', {
'start': DXFAttr(10, xtype=XType.point3d, default=(0, 0, 0)),
'end': DXFAttr(11, xtype=XType.point3d, default=(0, 0, 0)),
'thickness': DXFAttr(39, default=0, optional=True),
'extrusion': DXFAttr(210, xtype=XType.point3d, default=Vector(0.0, 0.0, 1.0), optional=True),
})
@register_entity
class Line(DXFGraphic):
""" The LINE entity represents a 3D line from `start` to `end` """
DXFTYPE = 'LINE'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_line)
def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
"""
Adds subclass processing for 'AcDbLine', requires previous base class and 'AcDbEntity' processing by parent
dxf = super().load_dxf_attribs(processor)
if processor:
tags = processor.load_dxfattribs_into_namespace(dxf, acdb_raster_variables)
if len(tags):
processor.log_unprocessed_tags(tags, subclass=acdb_raster_variables.name)
return dxf
def export_entity(self, tagwriter: 'TagWriter') -> None:
""" Export entity specific data as DXF tags. """
# base class export is done by parent class
super().export_entity(tagwriter)
tagwriter.write_tag2(SUBCLASS_MARKER, acdb_raster_variables.name)
self.dxf.export_dxf_attribs(tagwriter, ['class_version', 'frame', 'quality', 'units'])
acdb_wipeout_variables = DefSubclass('AcDbWipeoutVariables', {
'frame': DXFAttr(70, default=0), # Display-image-frame flag: 0 = No frame; 1 = Display frame
})
@register_entity
class WipeoutVariables(DXFObject):
""" DXF WIPEOUTVARIABLES entity """
DXFTYPE = 'WIPEOUTVARIABLES'
DXFATTRIBS = DXFAttributes(base_class, acdb_wipeout_variables)
MIN_DXF_VERSION_FOR_EXPORT = DXF2000
def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
dxf = super().load_dxf_attribs(processor)
if processor:
tags = processor.load_dxfattribs_into_namespace(dxf, acdb_wipeout_variables)
if len(tags):
if self.xrecord:
tagwriter.write_tags(self.xrecord)
if self.attached_mtext:
self.export_attached_mtext(tagwriter)
def export_acdb_attdef(self, tagwriter: 'TagWriter') -> None:
if tagwriter.dxfversion > DXF12:
tagwriter.write_tag2(SUBCLASS_MARKER, acdb_attdef.name)
# for all DXF versions
self.dxf.export_dxf_attribs(tagwriter, [
'version', 'prompt', 'tag', 'flags', 'field_length', 'valign', 'lock_position',
])
# DXF Reference for ATTRIB is a total mess and incorrect, AcDbText in Attrib same as in Text
acdb_attrib = DefSubclass('AcDbAttribute', {
'version': DXFAttr(280, default=0, dxfversion=DXF2010), # Version number: 0 = 2010
'tag': DXFAttr(2, default=''), # Tag string (cannot contain spaces)
'flags': DXFAttr(70, default=0),
# 1 = Attribute is invisible (does not appear)
# 2 = This is a constant attribute
# 4 = Verification is required on input of this attribute
# 8 = Attribute is preset (no prompt during insertion)
'field_length': DXFAttr(73, default=0, optional=True), # Field length (optional) (not currently used)
# Vertical text justification type (optional); see group code 73 in TEXT
'valign': DXFAttr(74, default=0, optional=True),
# Lock position flag. Locks the position of the attribute within the block reference
# example of double use of group codes in one sub class
'lock_position': DXFAttr(280, default=0, dxfversion=DXF2010, optional=True),
})
'defpoint3': DXFAttr(14, xtype=XType.point3d, default=(0.0, 0.0, 0.0)), # Definition point for linear and angular dimensions (in WCS)
'defpoint4': DXFAttr(15, xtype=XType.point3d, default=(0.0, 0.0, 0.0)), # Definition point for diameter, radius, and angular dimensions (in WCS)
'defpoint5': DXFAttr(16, xtype=XType.point3d, default=(0.0, 0.0, 0.0)), # Point defining dimension arc for angular dimensions (in OCS)
# The defpoint2 (13,23,33) and defpoint3 (14,24,34) specify the endpoints of the line used to determine the first
# extension line. Defpoint (10,20,30) and defpoint4 (15,25,35) specify the endpoints of the line used to determine
# the second extension line. Defpoint5 (16,26,36) specifies the location of the dimension line arc.
# The text_midpoint (11,21,31) specifies the midpoint of the dimension text.
# The point (15,25,35) specifies the vertex of the angle. The points (13,23,33)
# and (14,24,34) specify the endpoints of the extension lines. The point
# (10,20,30) specifies the location of the dimension line arc and the point
# (11,21,31) specifies the midpoint of the dimension text.
})
ordinate_dimension_subclass = DefSubclass('AcDbOrdinateDimension', {
'defpoint2': DXFAttr(13, xtype=XType.point3d, default=(0.0, 0.0, 0.0)), # Definition point for linear and angular dimensions (in WCS)
'defpoint3': DXFAttr(14, xtype=XType.point3d, default=(0.0, 0.0, 0.0)), # Definition point for linear and angular dimensions (in WCS)
# The defpoint1 (13,23,33) specifies the feature location and the defpoint2 (14,24,34) specifies the leader
# endpoint. The text_midpoint (11,21,31) specifies the midpoint of the dimension text. Defpoint (10,20,30) is placed
# at the origin of the UCS that is current when the dimension is created.
})
_DIMTXSTY = 'dimtxsty'
_DIMENSION_TPL = """ 0
DIMENSION
5
0
102
{ACAD_REACTORS
from .factory import register_entity
if TYPE_CHECKING:
from ezdxf.eztypes import TagWriter, Drawing, Vertex, DXFNamespace, UCS, Line, Arc, BaseLayout
__all__ = ['LWPolyline']
LWPointType = Tuple[float, float, float, float, float]
FORMAT_CODES = frozenset('xysebv')
DEFAULT_FORMAT = 'xyseb'
LWPOINTCODES = (10, 20, 40, 41, 42)
# Order doesn't matter, not valid for AutoCAD:
# If tag 90 is not the first TAG, AutoCAD does not close the polyline, when the `close` flag is set.
acdb_lwpolyline = DefSubclass('AcDbPolyline', {
'count': DXFAttr(90, xtype=XType.callback, getter='__len__'),
# always return actual length and set tag 90
'elevation': DXFAttr(38, default=0, optional=True),
'thickness': DXFAttr(39, default=0, optional=True),
'flags': DXFAttr(70, default=0),
'const_width': DXFAttr(43, optional=True),
'extrusion': DXFAttr(210, xtype=XType.point3d, default=Vector(0, 0, 1), optional=True),
# 10, 20 : Vertex x, y
# 91: vertex identifier ???
# 40, 41, 42: start width, end width, bulge
})
@register_entity
class LWPolyline(DXFGraphic):
""" DXF LWPOLYLINE entity """
from .dxfgfx import DXFGraphic, acdb_entity
from .dxfobj import DXFObject
from .objectcollection import ObjectCollection
from .factory import register_entity
if TYPE_CHECKING:
from ezdxf.eztypes import TagWriter, DXFNamespace, Tags, Drawing
__all__ = ['ACADTable']
acdb_block_reference = DefSubclass('AcDbBlockReference', {
'block_name': DXFAttr(2), # Block name; an anonymous block begins with a *T value
'insert': DXFAttr(10, xtype=XType.point3d, default=Vector(0, 0, 0)), # Insertion point
})
acdb_table = DefSubclass('AcDbTable', {
'version': DXFAttr(280), # Table data version number: 0 = 2010
'table_style_id': DXFAttr(342), # Hard pointer ID of the TABLESTYLE object
'block_record': DXFAttr(343), # Hard pointer ID of the owning BLOCK record
'horizontal_direction': DXFAttr(11), # Horizontal direction vector
'table_value': DXFAttr(90), # Flag for table value (unsigned integer)
'n_rows': DXFAttr(91), # Number of rows
'n_cols': DXFAttr(92), # Number of columns
'override_flag': DXFAttr(93), # Flag for an override
'border_color_override_flag': DXFAttr(94), # Flag for an override of border color
'border_lineweight_override_flag': DXFAttr(95), # Flag for an override of border lineweight
'border_visibility_override_flag': DXFAttr(96), # Flag for an override of border visibility
# 141: Row height; this value is repeated, 1 value per row
# 142: Column height; this value is repeated, 1 value per column
# for every cell:
# 171: Cell type; this value is repeated, 1 value per cell:
# 1 = text type
from ezdxf.math import Vector, Matrix44
from ezdxf.math.transformtools import OCSTransform, NonUniformScalingError
from ezdxf.lldxf.attributes import DXFAttr, DXFAttributes, DefSubclass, XType
from ezdxf.lldxf.const import DXF12, SUBCLASS_MARKER
from .dxfentity import base_class, SubclassProcessor
from .dxfgfx import DXFGraphic, acdb_entity, add_entity, replace_entity
from .factory import register_entity
from ezdxf.audit import AuditError
if TYPE_CHECKING:
from ezdxf.eztypes import TagWriter, DXFNamespace, Ellipse, Spline, Auditor
__all__ = ['Circle']
acdb_circle = DefSubclass('AcDbCircle', {
'center': DXFAttr(10, xtype=XType.point3d, default=Vector(0, 0, 0)),
'radius': DXFAttr(40, default=1),
'thickness': DXFAttr(39, default=0, optional=True),
'extrusion': DXFAttr(210, xtype=XType.point3d, default=(0, 0, 1), optional=True),
})
@register_entity
class Circle(DXFGraphic):
""" DXF CIRCLE entity """
DXFTYPE = 'CIRCLE'
DXFATTRIBS = DXFAttributes(base_class, acdb_entity, acdb_circle)
def load_dxf_attribs(self, processor: SubclassProcessor = None) -> 'DXFNamespace':
dxf = super().load_dxf_attribs(processor)
if processor: