1 # SPDX-License-Identifier: GPL-2.0-or-later
5 from mathutils
import Vector
8 _MESH_ENTITIES
= frozenset(["POLYFACE", "POLYMESH", "MESH", "POINT", "3DFACE", "SOLID", "TRACE"])
11 def mesh_entity(entity
):
12 return entity
.dxftype
in _MESH_ENTITIES
16 return typestr
in _MESH_ENTITIES
18 _POLYS
= frozenset(["LWPOLYLINE", "POLYLINE"])
20 def closed_poly_no_bulge(entity
):
21 return entity
.dxftype
in _POLYS
and not any([b
!= 0 for b
in entity
.bulge
]) and entity
.is_closed
24 _CURVE_ENTITIES
= frozenset(("POLYLINE", "POLYGON", "LWPOLYLINE", "SPLINE",
25 "CIRCLE", "ARC", "ELLIPSE", "LINE", "HELIX"))
27 def curve_entity(entity
):
28 return entity
.dxftype
in _CURVE_ENTITIES
32 return typestr
in _CURVE_ENTITIES
35 _NURBS_ENTITIES
= frozenset(("BODY", "REGION", "PLANESURFACE", "SURFACE", "3DSOLID"))
38 def nurbs_entity(entity
):
39 return entity
.dxftype
in _NURBS_ENTITIES
43 return typestr
in _NURBS_ENTITIES
46 _TEXT_ENTITIES
= frozenset(("MTEXT", "TEXT"))
49 def text_entity(entity
):
50 return entity
.dxftype
in _TEXT_ENTITIES
54 return typestr
in _TEXT_ENTITIES
57 def insert_entity(entity
):
58 return entity
.dxftype
== "INSERT"
62 return typestr
== "INSERT"
65 def light_entity(entity
):
66 return entity
.dxftype
== "LIGHT"
70 return typestr
== "LIGHT"
74 return entity
.dxftype
== "ATTDEF"
78 return typestr
== "ATTDEF"
81 _2D_ENTITIES
= frozenset(("CIRCLE", "ARC", "SOLID", "TRACE", "TEXT", "ATTRIB", "ATTDEF", "SHAPE",
82 "INSERT", "LWPOLYLINE", "HATCH", "IMAGE", "ELLIPSE"))
85 def _2D_entity(entity
):
86 return entity
.dxftype
in _2D_ENTITIES
or (entity
.dxftype
== "POLYGON" and entity
.mode
== "spline2d")
89 def varying_width(entity
):
90 if hasattr(entity
, "width"):
92 if hasattr(ew
, "__iter__"):
96 return ew
.count(ew
[0]) != len(ew
) or ew
[0][0] != ew
[0][1]
100 _SEPERATED_ENTITIES
= frozenset(("POLYFACE", "POLYMESH", "LIGHT", "MTEXT", "TEXT", "INSERT", "BLOCK"))
103 def separated_entity(entity
):
105 Indicates if the entity should be imported to one single Blender object or if it can be merged with other entities.
106 This depends not only on the type of a dxf-entity but also whether the width values are varying or all the same.
108 return entity
.dxftype
in _SEPERATED_ENTITIES
or varying_width(entity
)
111 def separated(typestr
):
112 return typestr
in _SEPERATED_ENTITIES
115 _NOT_COMBINED_ENTITIES
= frozenset(tuple(_SEPERATED_ENTITIES
) + ("ATTDEF",))
118 def combined_entity(entity
):
119 return not separated_entity(entity
) and not entity
.dxftype
== "ATTDEF"
122 def combined(typestr
):
123 return typestr
not in _NOT_COMBINED_ENTITIES
126 def extrusion(entity
):
127 if entity
.extrusion
is None:
129 return Vector(entity
.extrusion
) != Vector((0, 0, 1)) \
130 or (hasattr(entity
, "elevation") and entity
.elevation
!= 0)