11"""Viewport decorations"""
22import math
33from functools import reduce
4+ from itertools import chain
5+
46from bpy .types import SpaceView3D
57from mathutils import Vector
68import bpy
@@ -137,14 +139,23 @@ def __call__(self):
137139 drawing = self .props .drawings [self .props .active_drawing_index ]
138140 collection = bpy .data .collections .get ("IfcGroup/" + drawing .name )
139141
140- curves = [o for o in collection .objects if "IfcAnnotation/Dimension" in o .name ]
141- segments = []
142- for curve in curves :
143- segments .extend (list (self .iter_segments (curve )))
142+ segments = self .get_segments (self .get_curves (collection , "IfcAnnotation/Dimension" ))
143+
144+ self .draw_arrows (segments )
145+ for segm in segments :
146+ self .draw_label (segm , f"{ segm [2 ]:.2f} " )
147+
148+ segments = self .get_segments (self .get_curves (collection , "IfcAnnotation/Equal" ))
144149
145150 self .draw_arrows (segments )
146151 for segm in segments :
147- self .draw_label (segm )
152+ self .draw_label (segm , "EQ" )
153+
154+ def get_curves (self , collection , basename ):
155+ return list (filter (lambda o : basename in o .name , collection .objects ))
156+
157+ def get_segments (self , curves ):
158+ return list (chain .from_iterable (self .iter_segments (curve ) for curve in curves ))
148159
149160 def iter_segments (self , curve ):
150161 """Yields each segment converted to world coords
@@ -159,11 +170,11 @@ def iter_segments(self, curve):
159170 length = (p1 - p0 ).length
160171 yield (p0 , p1 , length )
161172
162- def draw_label (self , segm ):
173+ def draw_label (self , segm , text ):
163174 """Draw text of segment length
164175 aligned and centered at segment middle
165176 """
166- p0 , p1 , length = segm
177+ p0 , p1 , _ = segm
167178
168179 # convert to view coords
169180 region = self .context .region
@@ -175,8 +186,6 @@ def draw_label(self, segm):
175186 if proj .length < 0.001 :
176187 return
177188
178- text = f"{ length :.2f} "
179-
180189 ang = - Vector ((1 , 0 )).angle_signed (proj )
181190 cos = math .cos (ang )
182191 sin = math .sin (ang )
0 commit comments