23 raise FileNotFoundError(str.format( |
23 raise FileNotFoundError(str.format( |
24 '"{}" not found in the LDraw libraries', |
24 '"{}" not found in the LDraw libraries', |
25 filename, |
25 filename, |
26 )) |
26 )) |
27 |
27 |
|
28 def is_logo_stud_name(name): |
|
29 return name in ['stud.dat', 'stud3.dat'] |
|
30 |
28 class CyclicalReferenceError(Exception): |
31 class CyclicalReferenceError(Exception): |
29 pass |
32 pass |
30 |
33 |
31 class SubfileCache: |
34 class SubfileCache: |
32 class Subfile: |
35 class Subfile: |
33 def __init__(self): |
36 def __init__(self): |
34 self.valid = None |
37 self.valid = None |
35 self.flatness = None |
38 self.flatness = None |
36 self.description = None |
39 self.description = None |
37 self.problem = None |
40 self.problem = None |
|
41 self.has_studs = None # Whether or not it contains studs |
38 self.vertices = set() |
42 self.vertices = set() |
39 def __init__(self, ldraw_directories): |
43 def __init__(self, ldraw_directories): |
40 ''' |
44 ''' |
41 Initializes a new subfile cache |
45 Initializes a new subfile cache |
42 ''' |
46 ''' |
115 subfile.flatness.remove(dimension) |
119 subfile.flatness.remove(dimension) |
116 if not subfile.flatness: |
120 if not subfile.flatness: |
117 break |
121 break |
118 for subfile_reference in model.subfile_references: |
122 for subfile_reference in model.subfile_references: |
119 # Go through all the subfile references so that we catch any |
123 # Go through all the subfile references so that we catch any |
120 # cyclical references |
124 # cyclical references and to get studs |
121 self.prepare_file(subfile_reference.subfile_path) |
125 self.prepare_file(subfile_reference.subfile_path) |
|
126 subfile.has_studs = any( |
|
127 self.cache[subfile_reference.subfile_path].has_studs |
|
128 or is_logo_stud_name(subfile_reference.subfile_path) |
|
129 for subfile_reference in model.subfile_references |
|
130 ) |
122 self.reference_stack.pop() |
131 self.reference_stack.pop() |
123 |
132 |
124 if __name__ == '__main__': |
133 if __name__ == '__main__': |
125 cache = SubfileCache(ldraw_directories = ["~/ldraw"]) |
134 cache = SubfileCache(ldraw_directories = ["~/ldraw"]) |