summaryrefslogtreecommitdiff
path: root/creator/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'creator/base.py')
-rw-r--r--creator/base.py40
1 files changed, 26 insertions, 14 deletions
diff --git a/creator/base.py b/creator/base.py
index 2566a6b..603bef7 100644
--- a/creator/base.py
+++ b/creator/base.py
@@ -1,4 +1,5 @@
"""The base.py module contains parent classes for components."""
+
import numpy as np
import sys
import os.path
@@ -11,19 +12,23 @@ logging.basicConfig(filename='log.txt',
class Aircraft:
"""This class tracks all sub-components and is fed to the evaluator."""
- pass
+ def __init__(self, parent):
+ self.parent = parent
class Component:
"""Basic component providing coordinates and tools."""
-
- # TODO: define defaults in separate module
- def __init__(self):
+ def __init__(self, parent, name):
+ self.name = str()
+ self.parent = None
self.x = np.array([])
self.z = np.array([])
- self.material = str()
+ self.material = None
self.mass = float()
+ def __str__(self):
+ return self.name
+
def set_material(self, material):
"""Set the component bulk material."""
self.material = material
@@ -36,23 +41,30 @@ class Component:
print(name)
for k, v in self.__dict__.items():
if type(v) != list:
- print('{}:\n'.format(k), v)
+ print(f'{k}:\n', v)
print(num_of_dashes * '-')
for k, v in self.__dict__.items():
if type(v) == list:
- print('{}:\n'.format(k), np.around(v, round))
+ print(f'{k}:\n', np.around(v, round))
return None
- def info_save(self, save_path, number):
+ def info_save(self,
+ save_path='/home/blendux/Projects/Aircraft_Studio/save'):
"""Save all the object's coordinates (must be full path)."""
- file_name = f'{str(self).lower()}_{number}.txt'
+ file_name = f'{self.name}_info.txt'
full_path = os.path.join(save_path, file_name)
try:
- with open(full_path, 'w') as sys.stdout:
- self.info_print(6)
- # This line required to reset behavior of sys.stdout
- sys.stdout = sys.__stdout__
- logging.debug(f'Successfully wrote to file {full_path}')
+ with open(full_path, 'w') as f:
+ for k, v in self.__dict__.items():
+ if type(v) != list:
+ f.write(f'{k}:\n')
+ f.write(str(v))
+ # print(num_of_dashes * '-')
+ for k, v in self.__dict__.items():
+ if type(v) == list:
+ f.write(f'{k}:\n')
+ f.write(str(v))
+ logging.debug(f'Successfully wrote to file {full_path}')
except IOError:
print(f'Unable to write {file_name} to specified directory.\n',
'Was the full path passed to the function?')
Copyright 2019--2024 Marius PETER