-
Notifications
You must be signed in to change notification settings - Fork 14
/
airPlaneRib.py
383 lines (313 loc) · 15.2 KB
/
airPlaneRib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#################################################
#
# Airfoil creation - Aircraft
#
# Copyright (c) F. Nivoix - 2019 - V0.3
#
# For FreeCAD Versions = or > 0.17 Revision xxxx
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (LGPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# for detail see the LICENCE text file.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
################################################
__title__="FreeCAD airPlaneRib"
__author__ = "F. Nivoix"
__url__ = "https://fredsfactory.fr"
import FreeCAD,FreeCADGui,os,math
from PySide import QtCore
from PySide import QtGui
from airPlaneAirFoil import process
from airPlaneDesignProfilUI import SelectObjectUI
from airPlaneAirFoilNaca import generateNaca
import numpy as np
from App.xfoil.xfoil import XFoil
from App.xfoil.model import Airfoil
from App.xfoil.test import naca0012
import FreeCAD.Plot as Plot
FreeCADGui.addLanguagePath(":/translations")
smWB_icons_path = os.path.join( os.path.dirname(__file__), 'resources', 'icons')
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
class WingRib:
def __init__(self, obj,_profil,_nacagene,_nacaNbrPoint,_chord=100,_x=0,_y=0,_z=0,_xrot=0,_yrot=0,_zrot=0,_rot=0,_thickness=0,_useSpline = True,_finite_TE = False,_splitSpline = False):
'''Rib properties'''
obj.Proxy = self
obj.addProperty("App::PropertyFile","RibProfil","Rib",QtCore.QT_TRANSLATE_NOOP("App::Property","Profil type")).RibProfil=_profil
if _nacagene==True :
obj.addProperty("App::PropertyString","NacaProfil","NacaProfil",QtCore.QT_TRANSLATE_NOOP("App::Property","Naca Profil")).NacaProfil=_profil
else :
obj.addProperty("App::PropertyString","NacaProfil","NacaProfil",QtCore.QT_TRANSLATE_NOOP("App::Property","Naca Profil")).NacaProfil=""
obj.addProperty("App::PropertyInteger","NacaNbrPoint","NacaProfil",QtCore.QT_TRANSLATE_NOOP("App::Property","Naca Number of Points")).NacaNbrPoint=_nacaNbrPoint
obj.addProperty("App::PropertyBool","finite_TE","NacaProfil",QtCore.QT_TRANSLATE_NOOP("App::Property","Use a finite thickness at TE")).finite_TE=_finite_TE
obj.addProperty("App::PropertyBool","useSpline","Rib",QtCore.QT_TRANSLATE_NOOP("App::Property","use Spline")).useSpline =_useSpline
obj.addProperty("App::PropertyBool","splitSpline","Rib",QtCore.QT_TRANSLATE_NOOP("App::Property","split spline in lower and upper side")).splitSpline=_splitSpline
obj.addProperty("App::PropertyLength","Chord","Rib",QtCore.QT_TRANSLATE_NOOP("App::Property","Chord")).Chord=_chord
obj.addProperty("App::PropertyLength","Thickness","Rib",QtCore.QT_TRANSLATE_NOOP("App::Property","Thickness")).Thickness=_thickness
obj.addProperty("App::PropertyLength","wingkey","Rib",QtCore.QT_TRANSLATE_NOOP("App::Property","Wing Key"))
obj.addProperty("App::PropertyVectorList","Coordinates","Rib","Vector list that defines the airfoil's geometry").Coordinates=[]
obj.Placement=FreeCAD.Placement(FreeCAD.Vector(_x,_y,_z), FreeCAD.Rotation(FreeCAD.Vector(_xrot,_yrot,_zrot),_rot), FreeCAD.Vector(0,0,0))
# List Geometry to edit list of points
def onChanged(self, fp, prop):
'''Do something when a property has changed'''
if (str(prop) == "RibProfil") and (fp.PropertiesList.__contains__("Coordinates")):
print("Rib onChanged:")
fp.Coordinates=[]
if (str(prop)=="wingkey"):
print("Clef d'aile")
def execute(self, fp):
# Do something when doing a recomputation, this method is mandatory
#print("-------- Rib execute --------")
if fp.NacaProfil =="" :
face, fp.Coordinates=process(fp.RibProfil,
fp.Chord,
fp.Placement.Base.x,fp.Placement.Base.y,fp.Placement.Base.z,
fp.Placement.Rotation.Axis.x,fp.Placement.Rotation.Axis.y,fp.Placement.Rotation.Axis.z,
math.degrees(fp.Placement.Rotation.Angle),
fp.useSpline,fp.splitSpline,fp.Coordinates)
else :
face, fp.Coordinates=generateNaca(fp.NacaProfil, fp.NacaNbrPoint, fp.finite_TE,True,
fp.Chord,fp.Placement.Base.x,fp.Placement.Base.y,fp.Placement.Base.z,
fp.Placement.Rotation.Axis.x,fp.Placement.Rotation.Axis.y,fp.Placement.Rotation.Axis.z,
math.degrees(fp.Placement.Rotation.Angle),
fp.useSpline,fp.splitSpline)
#FreeCAD.Console.PrintMessage("After Rib generation\n")
#Xfoil
fp.Placement=FreeCAD.Placement(FreeCAD.Vector(fp.Placement.Base.x,fp.Placement.Base.y,fp.Placement.Base.z), FreeCAD.Rotation(FreeCAD.Vector(fp.Placement.Rotation.Axis.x,fp.Placement.Rotation.Axis.y,fp.Placement.Rotation.Axis.z),math.degrees(fp.Placement.Rotation.Angle)))#, FreeCAD.Vector(0,0,0))
if fp.Thickness != 0 :
fp.Shape = face.extrude(FreeCAD.Vector(0,fp.Thickness,0))
print("f")
else:
#fp.Shape = Part.Face(Part.Wire(fp.Coordinates))
fp.Shape = face
#fp.Placement=FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(fp.Placement.Rotation.Axis.x,fp.Placement.Rotation.Axis.y,fp.Placement.Rotation.Axis.z),fp.Placement.Rotation.Angle))
class RibTaskPanel:
'''A TaskPanel for the Rib'''
def __init__(self,vobj):
self.obj = vobj
path_to_ui = FreeCAD.getUserAppDataDir()+ 'Mod/AirPlaneDesign/resources/ribTaskPanel.ui'
self.form = FreeCADGui.PySideUic.loadUi(path_to_ui)
self.update(vobj)
self.form.xfoilSimulation.clicked.connect(self.xfoilSimulation)
def isAllowedAlterSelection(self):
return True
def isAllowedAlterView(self):
return True
def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Ok)
def updateGraphicsViewRib(self):
#coords=_coords
fp=self.obj.Object
coords=fp.Coordinates
for row_number,row_data in enumerate(coords):
self.form.profilTable.insertRow(row_number)
for col_number, data in enumerate(row_data):
self.form.profilTable.setItem(row_number,col_number,QtGui.QTableWidgetItem(str(data)))
scale=self.form.chord.value()*2
scene=QtGui.QGraphicsScene()
self.form.ribView.setScene(scene)
points=[]
first_v = None
last_v = None
for v in coords:
if first_v is None:
first_v = v
# End of if first_v is None
# Line between v and last_v if they're not equal
if (last_v != None) and (last_v != v):
points.append(QtCore.QPointF(last_v.x*scale,-last_v.z*scale ))
points.append(QtCore.QPointF(v.x*scale,-v.z*scale ))
# End of if (last_v != None) and (last_v != v)
# The new last_v
last_v = v
# End of for v in upper
# close the wire if needed
if last_v != first_v:
points.append(QtCore.QPointF(last_v.x*scale,-last_v.z*scale ))
points.append(QtCore.QPointF(first_v.x*scale,-first_v.z*scale ))
item=QtGui.QGraphicsPolygonItem(QtGui.QPolygonF(points))
item.setPen(QtGui.QPen(QtCore.Qt.blue))
scene.addItem(item)
self.form.ribView.setFocus()
self.form.ribView.show()
return
def update(self,vobj):
'fills the dialog with rib properties'
self.form.thickness.setValue(vobj.Object.Thickness)
self.form.chord.setValue(vobj.Object.Chord)
self.form.kingOfLines.setChecked(vobj.Object.useSpline)
self.form.fileName.setText(vobj.Object.RibProfil)
self.form.NACANumber.setText(vobj.Object.NacaProfil)
self.form.nacaNbrPoint.setValue(vobj.Object.NacaNbrPoint)
self.form.finite_TE.setChecked(vobj.Object.finite_TE)
for row_number,row_data in enumerate(vobj.Object.Coordinates):
self.form.profilTable.insertRow(row_number)
for col_number, data in enumerate(row_data):
self.form.profilTable.setItem(row_number,col_number,QtGui.QTableWidgetItem(str(data)))
self.updateGraphicsViewRib()
def accept(self):
'''Update properties of Rib'''
print("Update properties of Rib")
fp=self.obj.Object
fp.Thickness=self.form.thickness.value()
fp.Chord=self.form.chord.value()
fp.useSpline=self.form.kingOfLines.isChecked()
print("-bug-------------------------------")
fp.RibProfil=self.form.fileName.text()
print(self.form.fileName.text())
print("-bug-------------------------------")
FreeCAD.ActiveDocument.recompute()
FreeCADGui.ActiveDocument.resetEdit()
return True
def xfoilSimulation(self):
#naca0012 = Airfoil(x=np.array(),y=np.array)
xx=[]
yy=[]
for vect in self.obj.Object.Coordinates:
xx.append(vect[0])
yy.append(vect[2])
xf = XFoil()
xf.airfoil = Airfoil(np.array(xx),np.array(yy))#naca0012#
xf.max_iter = 40
# Cl=Cz coefficients de portance
# Cd =Cx coefficients de trainée
# Cm coefficients de moment
for i in [100000,200000,500000]:
xf.Re = i#1000000
#a, cl, cd, cm, cp = xf.aseq(-20, 20, 0.5)#xf.cseq(-0.5, 0.5, 0.05)#
cl, cd, cm, cp=xf.a(0)
print("a")
#print(a)
print("cl")
print(cl)
# trainée / portance
#Plot.plot(cm,a)
#Plot.plot(cl,a)
#Plot.plot(cd,a)
Plot.plot(cl,cd)
#Plot.plot(xx,yy)
#Plot.plot(xx,yy)
#Plot.plot(a,cm)
#Plot.plot(a,cl)
# Plot.plot(a,cd)
# Plot.plot(a,cm)
# Plot.plot(a,cp)
#Plot.plot(a,cm)
#Plot.plot(a,cd)
#Plot.plot(a,cl)
# print(a)
print(cl)
print("Profil")
print(naca0012)
def xfoilSimulation(self):
#naca0012 = Airfoil(x=np.array(),y=np.array)
xx=[]
yy=[]
for vect in self.obj.Object.Coordinates:
xx.append(vect[0])
yy.append(vect[2])
xf = XFoil()
xf.airfoil = Airfoil(np.array(xx),np.array(yy))#naca0012#
xf.max_iter = 40
# Cl=Cz coefficients de portance
# Cd =Cx coefficients de trainée
# Cm coefficients de moment
for i in [100000,200000,500000]:
xf.Re = i#1000000
#a, cl, cd, cm, cp = xf.aseq(-20, 20, 0.5)#xf.cseq(-0.5, 0.5, 0.05)#
cl, cd, cm, cp=xf.a(0)
print("a")
#print(a)
print("cl")
print(cl)
# trainée / portance
#Plot.plot(cm,a)
#Plot.plot(cl,a)
#Plot.plot(cd,a)
Plot.plot(cl,cd)
#Plot.plot(xx,yy)
#Plot.plot(xx,yy)
#Plot.plot(a,cm)
#Plot.plot(a,cl)
# Plot.plot(a,cd)
# Plot.plot(a,cm)
# Plot.plot(a,cp)
#Plot.plot(a,cm)
#Plot.plot(a,cd)
#Plot.plot(a,cl)
# print(a)
print(cl)
print("Profil")
print(naca0012)
def retranslateUi(self, TaskPanel):
#TaskPanel.setWindowTitle(QtGui.QApplication.translate("draft", "Faces", None))
self.addButton.setText(QtGui.QApplication.translate("draft", "Update", None))
class ViewProviderWingRib:
def __init__(self, obj):
'''Set this object to the proxy object of the actual view provider'''
obj.Proxy = self
def getDefaultDisplayMode(self):
'''Return the name of the default display mode. It must be defined in getDisplayModes.'''
return "Flat Lines"
def getIcon(self):
'''Return the icon in XPM format which will appear in the tree view. This method is\
optional and if not defined a default icon is shown.'''
return os.path.join(smWB_icons_path,'rib.xpm')
def __getstate__(self):
'''When saving the document this object gets stored using Python's json module.\
Since we have some un-serializable parts here -- the Coin stuff -- we must define this method\
to return a tuple of all serializable objects or None.'''
return None
def __setstate__(self, state):
'''When restoring the serialized object from document we have the chance to set some internals here.\
Since no data were serialized nothing needs to be done here.'''
return None
def dumps(self):
'''When saving the document this object gets stored using Python's json module.\
Since we have some un-serializable parts here -- the Coin stuff -- we must define this method\
to return a tuple of all serializable objects or None.'''
return None
def loads(self, state):
'''When restoring the serialized object from document we have the chance to set some internals here.\
Since no data were serialized nothing needs to be done here.'''
return None
def setEdit(self,vobj,mode):
taskd = RibTaskPanel(vobj)
FreeCADGui.Control.showDialog(taskd)
return True
class CommandWingRib:
"the WingPanel command definition"
def GetResources(self):
iconpath = os.path.join(smWB_icons_path,'rib.svg')
return {'Pixmap': iconpath, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Create_a_Rib","Create a Rib")}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
def Activated(self):
editor = SelectObjectUI()
editor.setupUi()
r = editor.form.exec_()
if r:
if editor.form.NACANumber.text()=="" :
b=editor.filePath
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","wrib")
WingRib(a,b,False,0,editor.form.chord.value(),0,0,0,1,0,0,0,editor.form.thickness.value(),editor.form.useSpline.isChecked(),_splitSpline=editor.form.splitSpline.isChecked())
ViewProviderWingRib(a.ViewObject)
else :
b=editor.form.NACANumber
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","wrib")
WingRib(a,b.text(),True,int(editor.form.nacaNbrPoint.value()),editor.form.chord.value(),0,0,0,1,0,0,0,editor.form.thickness.value(),editor.form.useSpline.isChecked(),editor.form.finite_TE.isChecked(),editor.form.splitSpline.isChecked())
ViewProviderWingRib(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
else :
FreeCAD.Console.PrintMessage("Rib creation canceled")
if FreeCAD.GuiUp:
#Register the FreeCAD command
FreeCADGui.addCommand('airPlaneDesignWRib',CommandWingRib())