[Breaking change] Compound Filter: change the way specific items of compoundFilter are parsed
Used to be: 1,2,5-10 (ranges inclusive) Now: 1,2,5:11:1 (like python lists) Now 'to' number is not-inclusive; dash replaced with colon (to support negatives); added support for missing values; added support of step
This commit is contained in:
parent
e808beef2f
commit
be55ccebfa
|
@ -57,7 +57,7 @@ class _CompoundFilter:
|
|||
obj.FilterType = 'bypass'
|
||||
|
||||
# properties controlling "specific items" mode
|
||||
obj.addProperty("App::PropertyString","items","CompoundFilter","list of indexes of childs to be returned (like this: 1,4,8-10)")
|
||||
obj.addProperty("App::PropertyString","items","CompoundFilter","list of indexes of childs to be returned (like this: 1,4,8:10).")
|
||||
|
||||
obj.addProperty("App::PropertyLink","Stencil","CompoundFilter","Object that defines filtering")
|
||||
|
||||
|
@ -90,16 +90,17 @@ class _CompoundFilter:
|
|||
flags = [False] * len(shps)
|
||||
ranges = obj.items.split(';')
|
||||
for r in ranges:
|
||||
r_v = r.split('-')
|
||||
r_v = r.split(':')
|
||||
if len(r_v) == 1:
|
||||
i = int(r_v[0])
|
||||
rst.append(shps[i])
|
||||
flags[i] = True
|
||||
elif len(r_v) == 2:
|
||||
ifrom = int(r_v[0])
|
||||
ito = int(r_v[1])+1 #python treats range's 'to' value as not-inclusive. I want the string to list in inclusive manner.
|
||||
rst=rst+shps[ifrom:ito]
|
||||
for b in flags[ifrom:ito]:
|
||||
elif len(r_v) == 2 or len(r_v) == 3:
|
||||
ifrom = None if len(r_v[0].strip()) == 0 else int(r_v[0])
|
||||
ito = None if len(r_v[1].strip()) == 0 else int(r_v[1])
|
||||
istep = None if len(r_v[2].strip()) == 0 else int(r_v[2])
|
||||
rst=rst+shps[ifrom:ito:istep]
|
||||
for b in flags[ifrom:ito:istep]:
|
||||
b = True
|
||||
else:
|
||||
raise ValueError('index range cannot be parsed:'+r)
|
||||
|
|
Loading…
Reference in New Issue
Block a user