--- a/tests/subfiles.py Mon Jun 24 00:28:37 2019 +0300 +++ b/tests/subfiles.py Mon Jun 24 00:18:49 2019 +0300 @@ -102,6 +102,18 @@ scaling = scaling, ) +def subfile_references_with_invertnext(model): + import linetypes + has_invertnext = False + for element in model.body: + if isinstance(element, linetypes.MetaCommand) \ + and element.text == 'BFC INVERTNEXT': + has_invertnext = True + else: + if isinstance(element, linetypes.SubfileReference): + yield element, has_invertnext + has_invertnext = False + @problem_type('cyclical-reference', severity = 'hold', message = lambda chain: @@ -132,6 +144,10 @@ scaling = scaling_description(scaling_vector), ), ) +@problem_type('unnecessary-invertnext', + severity = 'warning', + message = 'flat subfile unnecessarily inverted using BFC INVERTNEXT' +) def dependent_subfile_tests(model): ''' Tests subfile references for such qualities that are dependent on the @@ -141,7 +157,7 @@ import filecache cache = filecache.SubfileCache(model.ldraw_directories) failed_subfiles = set() - for subfile_reference in model.subfile_references: + for subfile_reference, has_invertnext in subfile_references_with_invertnext(model): path = subfile_reference.subfile_path.lower() if path in failed_subfiles: # Already proven to be a bad apple, don't complain twice @@ -165,6 +181,7 @@ ) failed_subfiles.add(path) else: + # Test for use of moved-to files import re match = re.search(r'^\~Moved(?: to (\w+))?$', subfile.description) if match: @@ -174,6 +191,7 @@ moved_file = path, new_file = match.group(1), ) + # Test for scaling in flat direction scaling_vector = subfile_reference.matrix.scaling_vector() scaled_dimensions = { dimension @@ -192,6 +210,12 @@ scaled_flat_dimensions = scaled_flat_dimensions, scaling_vector = scaling_vector, ) + # Test whether a flat subfile is inverted using invertnext + if has_invertnext and subfile.flatness: + yield report_problem( + 'unnecessary-invertnext', + bad_object = subfile_reference, + ) def dimensions_description(dimensions): if isinstance(dimensions, str):