1 # SPDX-FileCopyrightText: 2014-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
7 from mathutils
import Vector
10 def map_dxf_to_blender_type(TYPE
):
12 TYPE: DXF entity type (String)
19 return "object_surface"
21 print("groupsort: not mergeable type ", TYPE
)
22 return "not_mergeable"
25 def by_blender_type(entities
):
27 entities: list of DXF entities
29 keyf
= lambda e
: map_dxf_to_blender_type(e
.dxftype
)
30 return itertools
.groupby(sorted(entities
, key
=keyf
), key
=keyf
)
33 def by_layer(entities
):
35 entities: list of DXF entities
37 keyf
= lambda e
: e
.layer
38 return itertools
.groupby(sorted(entities
, key
=keyf
), key
=keyf
)
40 def by_closed_poly_no_bulge(entities
):
42 entities: list of DXF entities
44 keyf
= lambda e
: is_
.closed_poly_no_bulge(e
)
45 return itertools
.groupby(sorted(entities
, key
=keyf
), key
=keyf
)
48 def by_dxftype(entities
):
50 entities: list of DXF entities
52 keyf
= lambda e
: e
.dxftype
53 return itertools
.groupby(sorted(entities
, key
=keyf
), key
=keyf
)
56 def by_attributes(entities
):
58 entities: list of DXF entities
59 attributes: thickness and width occurring in curve types; subdivision_levels occurring in MESH dxf types
61 def attributes(entity
):
64 extrusion
= entity
.extrusion
65 if hasattr(entity
, "width"):
66 if any((w
!= 0 for ww
in entity
.width
for w
in ww
)):
68 if hasattr(entity
, "subdivision_levels"):
69 subd
= entity
.subdivision_levels
70 if entity
.dxftype
in {"LINE", "POINT"}:
71 extrusion
= (0.0, 0.0, 1.0)
73 # This can happen for entities of type "SPLINE" for example.
74 # But the sort comparison does not work between 'tuple' and 'NoneType'.
76 return entity
.thickness
, subd
, width
, extrusion
78 return itertools
.groupby(sorted(entities
, key
=attributes
), key
=attributes
)
80 def by_insert_block_name(inserts
):
82 entities: list of DXF inserts
84 keyf
= lambda e
: e
.name
85 return itertools
.groupby(sorted(inserts
, key
=keyf
), key
=keyf
)