feat: Name in target

This commit is contained in:
Leni Aniva 2024-07-04 10:02:58 -07:00
parent d69cf014a1
commit 89c6a39c2f
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
2 changed files with 27 additions and 11 deletions

View File

@ -42,14 +42,20 @@ class Target:
self.kind = kind
self.kwargs = kwargs
def __str__(self):
return f"<target {self.name}>"
return f"<target {self.name}.{self.kind.ext} {self._method}>"
def __call__(self, obj, *args, **kwargs):
"""
Raw call function which passes arguments directly to `_method`
"""
return self._method(obj, *args, **kwargs)
def file_name(self, file_name):
return f"{file_name}.{self.kind.ext}"
@property
def file_name(self):
"""
Output file name
"""
return f"{self.name}.{self.kind.ext}"
def write_to(self, obj, path: str):
x = self._method(obj)
if self.kind == TargetKind.STL:
@ -98,6 +104,8 @@ class Model:
"""
Base class for a parametric assembly
"""
def __init__(self, name: str):
self.name = name
@property
def target_names(self) -> list[str]:
@ -107,19 +115,22 @@ class Model:
return list(Target.methods(self).keys())
def check_all(self) -> int:
"""
Builds all targets but do not output them
"""
total = 0
for k, f in Target.methods(self).items():
f(self)
for t in Target.methods(self).values():
t(self)
total += 1
return total
def build_all(self, output_dir: Union[Path, str] = "build", verbose=1):
"""
Build all targets in this model
Build all targets in this model and write the results to file
"""
output_dir = Path(output_dir)
for k, target in Target.methods(self).items():
output_file = output_dir / target.file_name(k)
for t in Target.methods(self).values():
output_file = output_dir / self.name / t.file_name
if output_file.is_file():
if verbose >= 1:
print(f"{Fore.GREEN}Skipping{Style.RESET_ALL} {output_file}")
@ -128,6 +139,10 @@ class Model:
if verbose >= 1:
print(f"{Fore.BLUE}Building{Style.RESET_ALL} {output_file}")
target.write_to(self, str(output_file))
if verbose >= 1:
print(f"{Fore.GREEN}Built{Style.RESET_ALL} {output_file}")
try:
t.write_to(self, str(output_file))
if verbose >= 1:
print(f"{Fore.GREEN}Built{Style.RESET_ALL} {output_file}")
except Exception as e:
print(f"{Fore.RED}Failed to build{Style.RESET_ALL} {output_file}: {e}")

View File

@ -109,6 +109,7 @@ class Parameters(Model):
))
def __post_init__(self):
super().__init__(name="houjuu-nue")
assert self.wing_root_radius > self.hs_hirth_joint.radius,\
"Wing root must be large enough to accomodate joint"