From be55ccebfa62f115b91b7a5a882d0a6835c82c90 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Fri, 6 Nov 2015 02:08:15 +0300 Subject: [PATCH] [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 --- CompoundFilter.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/CompoundFilter.py b/CompoundFilter.py index 6a062b8..715b57d 100644 --- a/CompoundFilter.py +++ b/CompoundFilter.py @@ -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)