[Python] Design & build airplanes from your specifications.
1
"""The base. module contains parent classes for components."""
2
3
import numpy as np
4
import os.
5
import random
6
import logging
7
8
from aircraftstudio import creator
9
10
logging.(filename='log_base.txt',
11
level=.DEBUG,
12
format='%(asctime)s - %(levelname)s - %(message)s')
13
14
15
class Aircraft:
16
"""This class tracks all sub-components and is fed to the evaluator."""
17
name = None
18
fuselage = None
19
propulsion = None
20
wing = None
21
properties = {}
22
23
naca = [2412, 3412, 2420]
24
25
def __init__(self):
26
self. = {}
27
28
def __str__(self):
29
return self.
30
31
@classmethod
32
def (cls):
33
aircraft = ()
34
aircraft. = 'default_aircraft_' + str(.(1000,9999))
35
airfoil = creator..(,'default_airfoil')
36
airfoil.(2412)
37
soar1 = creator..(,'default_spar_1',0.30)
38
soar2 = creator..(,'default_spar_2',0.60)
39
stringer = creator..(,'default_stringer')
40
return aircraft
41
42
@classmethod
43
def (cls):
44
aircraft = ()
45
aircraft. = 'random_aircraft_' + str(.(1000,9999))
46
airfoil = creator..(,'random_airfoil')
47
airfoil.(.(cls.))
48
soar1 = creator..(,'random_spar_1',
49
.(20,80)/100)
50
soar2 = creator..(,'random_spar_2',
51
.(20,80)/100)
52
stringer = creator..(,'random_stringer',
53
.(1,10),
54
.(1,10),
55
.(1,10),
56
.(1,10))
57
return aircraft
58
59
60
class Component:
61
"""Basic component providing coordinates, tools and a component tree."""
62
def __init__(self,,):
63
self. = parent
64
self. = name
65
self. = np.([])
66
self. = np.([])
67
self. = np.([])
68
self. = None
69
self. = float()
70
self. = {}
71
72
def __str__(self):
73
return self.
74
75
def (self,round):
76
"""Print all the component's coordinates to the terminal."""
77
name = f' CREATOR DATA FOR {str(self).()} '
78
num_of_dashes = len()
79
print(*'-')
80
print()
81
for k, v in self.__dict__.():
82
if type() is not np.:
83
print(f'{}:\n',)
84
print(*'-')
85
for k, v in self.__dict__.():
86
if type() is np.:
87
print(f'{}:\n',.(,round))
88
return None
89
90
def (self,
91
save_path='/home/blendux/Projects/Aircraft_Studio/save'):
92
"""Save all the object's coordinates (must be full path)."""
93
file_name = f'{self.}_info.txt'
94
full_path = os..(,)
95
try:
96
with open(,'w') as f:
97
for k, v in self.__dict__.():
98
if type() is not np.:
99
f.(f'{}=\n')
100
f.(str())
101
f.("\n")
102
# print(num_of_dashes * '-')
103
for k, v in self.__dict__.():
104
if type() is np.:
105
f.(f'{}=\n')
106
f.(str())
107
f.("\n")
108
logging.(f'Successfully wrote to file {}')
109
except IOError:
110
print(f'Unable to write {} to specified directory.\n',
111
'Was the full path passed to the function?')
112
return None
113