BREAKING change shape identifers generated when flattening
This commit is contained in:
parent
db4148a0ff
commit
a5900f6ade
@ -546,35 +546,31 @@ class Pattern(LockableImpl, AnnotatableImpl, Mirrorable, metaclass=AutoSlots):
|
|||||||
"""
|
"""
|
||||||
Removes all subpatterns and adds equivalent shapes.
|
Removes all subpatterns and adds equivalent shapes.
|
||||||
|
|
||||||
Shape identifiers are changed to represent their original position in the
|
Shape/label identifiers are changed to represent their original position in the
|
||||||
pattern hierarchy:
|
pattern hierarchy:
|
||||||
`(L1_name (str), L1_index (int), L2_name, L2_index, ..., *original_shape_identifier)`
|
`(L1_sp_index (int), L2_sp_index (int), ..., sh_index (int), *original_shape_identifier)`
|
||||||
where
|
where the original shape can be accessed as e.g.
|
||||||
`L1_name` is the first-level subpattern's name (e.g. `self.subpatterns[0].pattern.name`),
|
`self.subpatterns[L1_sp_index].pattern.subpatterns[L2_sp_index].shapes[L1_sh_index]`
|
||||||
`L2_name` is the next-level subpattern's name (e.g.
|
|
||||||
`self.subpatterns[0].pattern.subpatterns[0].pattern.name`) and
|
|
||||||
`L1_index` is an integer used to differentiate between multiple instance ofi the same
|
|
||||||
(or same-named) subpatterns.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
self
|
self
|
||||||
"""
|
"""
|
||||||
subpatterns = copy.deepcopy(self.subpatterns)
|
subpatterns = copy.deepcopy(self.subpatterns)
|
||||||
self.subpatterns = []
|
self.subpatterns = []
|
||||||
shape_counts: Dict[Tuple, int] = {}
|
|
||||||
for subpat in subpatterns:
|
# Update identifiers so each shape has a unique one
|
||||||
|
for ss, shape in enumerate(self.shapes):
|
||||||
|
shape.identifier = (ss,) + shape.identifier
|
||||||
|
for ll, label in enumerate(self.labels):
|
||||||
|
label.identifier = (ll,) + label.identifier
|
||||||
|
|
||||||
|
for pp, subpat in enumerate(subpatterns):
|
||||||
if subpat.pattern is None:
|
if subpat.pattern is None:
|
||||||
continue
|
continue
|
||||||
subpat.pattern.flatten()
|
subpat.pattern.flatten()
|
||||||
p = subpat.as_pattern()
|
p = subpat.as_pattern()
|
||||||
|
for item in chain(p.shapes, p.labels):
|
||||||
# Update identifiers so each shape has a unique one
|
item.identifier += (pp,) + item.identifier
|
||||||
for shape in p.shapes:
|
|
||||||
combined_identifier = (subpat.pattern.name,) + shape.identifier
|
|
||||||
shape_count = shape_counts.get(combined_identifier, 0)
|
|
||||||
shape.identifier = (subpat.pattern.name, shape_count) + shape.identifier
|
|
||||||
shape_counts[combined_identifier] = shape_count + 1
|
|
||||||
|
|
||||||
self.append(p)
|
self.append(p)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user