21 config['libraries'] = ['/path/to/ldraw'] |
21 config['libraries'] = ['/path/to/ldraw'] |
22 if config != read_config: |
22 if config != read_config: |
23 config.write() |
23 config.write() |
24 return config |
24 return config |
25 |
25 |
26 def read_ldraw(file, *, config): |
26 def read_ldraw(file, *, name = '', config): |
27 result = list() |
27 model_body = [ |
28 for line in file: |
28 parse_ldraw_code(line) |
29 result.append(parse_ldraw_code(line)) |
29 for line in file |
30 return result |
30 ] |
|
31 model = Model(body = model_body) |
|
32 model.name = name |
|
33 return model |
31 |
34 |
32 def library_paths(config): |
35 def library_paths(config): |
33 for library_path_string in config['libraries']: |
36 for library_path_string in config['libraries']: |
34 yield Path(library_path_string).expanduser() |
37 yield Path(library_path_string).expanduser() |
35 |
38 |
47 |
50 |
48 class Model: |
51 class Model: |
49 def __init__(self, body): |
52 def __init__(self, body): |
50 self.body = body |
53 self.body = body |
51 self.body_offset = 0 |
54 self.body_offset = 0 |
52 @property |
55 def filter_by_type(self, type): |
53 def quadrilaterals(self): |
|
54 yield from [ |
56 yield from [ |
55 element |
57 element |
56 for element in self.body |
58 for element in self.body |
57 if isinstance(element, linetypes.Quadrilateral) |
59 if isinstance(element, type) |
58 ] |
60 ] |
|
61 @property |
|
62 def subfile_references(self): |
|
63 yield from self.filter_by_type(linetypes.SubfileReference) |
|
64 @property |
|
65 def line_segments(self): |
|
66 yield from self.filter_by_type(linetypes.LineSegment) |
|
67 @property |
|
68 def triangles(self): |
|
69 yield from self.filter_by_type(linetypes.Triangle) |
|
70 @property |
|
71 def quadrilaterals(self): |
|
72 yield from self.filter_by_type(linetypes.Quadrilateral) |
59 |
73 |
60 if __name__ == '__main__': |
74 if __name__ == '__main__': |
61 from sys import argv |
75 from sys import argv |
62 config = load_config('ldcheck.cfg') |
76 config = load_config('ldcheck.cfg') |
63 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config): |
77 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config): |
64 with ldconfig_ldr_path.open() as ldconfig_ldr: |
78 with ldconfig_ldr_path.open() as ldconfig_ldr: |
65 load_colours(ldconfig_ldr) |
79 load_colours(ldconfig_ldr) |
66 with open(argv[1], 'r') as file: |
80 with open(argv[1], 'r') as file: |
67 model_body = read_ldraw(file, config = config) |
|
68 model = Model(body = model_body) |
|
69 from os.path import basename |
81 from os.path import basename |
70 model.name = basename(argv[1]) |
82 model = read_ldraw(file, name = basename(argv[1]), config = config) |
71 from testsuite import load_tests, check_model, format_report |
83 from testsuite import load_tests, check_model, format_report |
72 test_suite = load_tests() |
84 test_suite = load_tests() |
73 report = check_model(model, test_suite) |
85 report = check_model(model, test_suite) |
74 print(format_report(report, model, test_suite)) |
86 print(format_report(report, model, test_suite)) |